Console printing without scrolling

Hi guys, I saw console applications print colors and saw applications like ffmpeg print text on top of themselves, not a new line. How to print over an existing line? I want to display fps in my console application either at the very top or at the very bottom and have regular printfs, and scroll normally

-edit- I need this for windows, but it should be cross-platform, so in the end I will have a linux and mac implementation

+5
source share
7 answers

There are two simple features that work with both linux and windows, but for only one line:

  • printf("\b"); , , , , n
    printf("\b\b\b\b\b\b\b\b\b\b");
  • printf("text to be overwritten by next printf\r"); , printf . , .

, , ncurses, , ANSI.

edit: ​​ wikipedia ncurses, , , ,

+18

'\r' '\n'.

+3

ASCII 8 (A.K.A. Ctrl-H, BS Backspace) . ASCII 13 (A.K.A Ctrl-M, CR ) .

C, putchar(8); putchar(13);

+2

ncurses. .

+2

, .. ANSI escape-. , ANSI, , (.. bash script printf() C).

Unix- escape- ANSI Windows, MS-DOS-, . . ANSI Windows. , Cygwin Windows, ANSI , Unix.

Ncurses, - GUI- . , , , ( Windows/Unix), , , , , (.. ). ncurses , API, , escape- ANSI , , .

ANSI- Linux, :

PS1="\[\033[34m\][\$(date +%H%M)][\u@\h:\w]$ "
+2

Ncurses -

ncurses package - , ,

+1

, , , , API, , ASCII.

eg. If you are working with Win32, you can directly manipulate the console screen buffer.

A good place to start can be here http://msdn.microsoft.com/en-us/library/ms683171(VS.85).aspx

I was looking for similar functions / APIs that would allow me to access the console as something different from text flow for other platforms. They have not found anything yet, but again, I did not look so hard.

Hope this helps.

+1
source

All Articles