C/C++, How do you code for the download progress thing in the CLI? Linux

时间:2022-04-26 04:59:56

Im looking to make program with a similar feature as the Download Progress Text with the arrow going across.. Example PIC is a reference to what im talking about.

我希望使用与箭头相交的下载进度文本类似的功能制作程序。示例PIC是我正在谈论的内容的参考。

Any libraries or designs with basic functions? Thanks for any help!

任何具有基本功能的库或设计?谢谢你的帮助!

3 个解决方案

#1


1  

The library you are looking for is ncurses. It can be found here.

您正在寻找的图书馆是ncurses。在这里能找到它。

Here is another resource I found for ncurses that may be useful to help introduce you to the library and its functionality. It's a series of Youtube tutorials -- his speaking is poor but from what I can tell (listening only to the first two videos) his examples are sufficiently well taught.

这是我为ncurses找到的另一个资源,可能有助于向您介绍库及其功能。这是一系列Youtube教程 - 他的演讲很糟糕,但从我能讲的(只听前两个视频)他的例子得到了很好的教导。

#2


0  

You may use boost::progress_display

你可以使用boost :: progress_display

#3


0  

If all you want is a progress bar for some data, you should check out pv. One way to use it is to simply pipe your data through the program. Here is a simple example below that just reads in a file using a call to pv with popen():

如果你想要的只是一些数据的进度条,你应该看看光伏。使用它的一种方法是简单地通过程序管道数据。下面是一个简单的示例,只需使用popen()调用pv即可读取文件:

#include <stdio.h>

int main (int argc, char *argv[]) {
    char pv[1024];
    FILE *infile;
    if (argc > 1) {
        char c;
        snprintf(pv, sizeof(pv), "pv %s", argv[1]);
        infile = popen(pv, "r");
        while (fread(&c, 1, 1, infile)) {}
        pclose(infile);
    } else {
        puts("need a file name!");
    }
    return 0;
}

#1


1  

The library you are looking for is ncurses. It can be found here.

您正在寻找的图书馆是ncurses。在这里能找到它。

Here is another resource I found for ncurses that may be useful to help introduce you to the library and its functionality. It's a series of Youtube tutorials -- his speaking is poor but from what I can tell (listening only to the first two videos) his examples are sufficiently well taught.

这是我为ncurses找到的另一个资源,可能有助于向您介绍库及其功能。这是一系列Youtube教程 - 他的演讲很糟糕,但从我能讲的(只听前两个视频)他的例子得到了很好的教导。

#2


0  

You may use boost::progress_display

你可以使用boost :: progress_display

#3


0  

If all you want is a progress bar for some data, you should check out pv. One way to use it is to simply pipe your data through the program. Here is a simple example below that just reads in a file using a call to pv with popen():

如果你想要的只是一些数据的进度条,你应该看看光伏。使用它的一种方法是简单地通过程序管道数据。下面是一个简单的示例,只需使用popen()调用pv即可读取文件:

#include <stdio.h>

int main (int argc, char *argv[]) {
    char pv[1024];
    FILE *infile;
    if (argc > 1) {
        char c;
        snprintf(pv, sizeof(pv), "pv %s", argv[1]);
        infile = popen(pv, "r");
        while (fread(&c, 1, 1, infile)) {}
        pclose(infile);
    } else {
        puts("need a file name!");
    }
    return 0;
}