Vcvv
Vcvv

Reputation: 71

How to display many progress bars in console Linux ?

I am trying to create simple app using c in Ubuntu, which will copy folder to other place. Every file has to be copied in separate thread and in console I want to see the progress about every copied file. Usually I am using

printf("document1.txt #######                 %d \n", progress);

I know that I can overwrite a line using \r But how can I move between lines ?

I just want to see in console something like this:

document1.txt: ###########=>                   30% is done
video1.txt:    ##=>                             5% is done
video2.txt:    ######################=>        70% is done

Upvotes: 2

Views: 313

Answers (1)

jwdonahue
jwdonahue

Reputation: 6659

See ANSI escape code, on Wikipedia. As Ahmed Masud points out, there's curses/ncurses libraries that put an API on top of these code sequences.

A common approach is to simply clear the screen and print a full page of data. Most systems do this quickly enough today that it can be acceptably flicker free, but writing only into the cells on the screen that have changed, is much more reliably flicker free.

EDIT: Additional references:

Upvotes: 2

Related Questions