Reputation: 180
As you probably know, when you run the "top" command in a terminal, it will show you the busiest processes on your computer and update the values periodically without adding a single line.
What is the technique called that allows it do this — to change the printed string from a CLI program?
Upvotes: 4
Views: 156
Reputation: 409356
One way is to get the get the width/height of the terminal window, and just clear/print whole screen every time. Another way is to use VT100 escape codes to reposition cursor and overwrite whats on that position. A third way is to use a library such as ncurses
.
Upvotes: 3
Reputation: 143219
Terminal accepts some control sequences for screen positioning, etc. Look into curses
/ncurses
library. Also, if you want to modify just one line you can do with just using \r
and printing over that line again.
Upvotes: 2