-2

I have a program that is a simulation, it updates constantly and writes messages in terminal, however, this causes the terminal to constantly scroll with new lines. I am wondering if there is a way to make terminal print lines and then clear after 10 seconds and then update?

  • I don't think there's a way to make this happen automatically. Use the `ncurses` library in your program to display your data in the way you want. – Barmar Oct 28 '21 at 23:35
  • Depends on the terminal. You can use escape sequences (<- search keyword). Or, one fairly simple way is to just print `\b` backspaces to delete the previous text (and don't print a newline at the end, just `fflush` the output). – Arkku Oct 28 '21 at 23:36
  • https://stackoverflow.com/questions/2347770/how-do-you-clear-the-console-screen-in-c – Joe McGorry Oct 29 '21 at 00:13

1 Answers1

0

Many terminals accept special escape codes allowing the programmer to move the cursor, set the colour and many more functions.

To use it good people wrote the ncurses library https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/

0___________
  • 60,014
  • 4
  • 34
  • 74