2

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
Vcvv
  • 71
  • 4
  • 2
    Show the relevant code, and point to a specific problem. As is, this appears to be a _can you write my code for me_ type of request. – ryyker Nov 04 '17 at 21:33
  • 2
    hint: `man curses` or `man ncurses` – Ahmed Masud Nov 04 '17 at 21:35
  • hey, thanks for answer, but I don't know how to start, I will read about this libraries curses and ncurses. Is there a possibility to do this without some library ? – Vcvv Nov 04 '17 at 21:42
  • Here is a very terse, but useful primer: _[C Primer/C Console IO](https://en.wikibooks.org/wiki/A_Little_C_Primer/C_Console_IO)_ – ryyker Nov 04 '17 at 21:46

1 Answers1

2

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:

jwdonahue
  • 6,199
  • 2
  • 21
  • 43