Is there any way to clear specific number of lines in a terminal?

by Abhishek Soni   Last Updated July 17, 2017 10:01 AM

Here's the use case:

  1. A node.js script clears the console.
  2. Then it sends some metadata to the console. (Module Name, and tagline. Sort of like an App's header.)

  3. It sends past data to the console. (Sort of like an App's initial content, which, since it's past, will not change after issuing. At least, not until exiting.)

  4. It does what it's supposed to, what the module was made for, and it pipes that to the console as well.

Step 4 is a continuous process. And hence you can think of Step 4 as if it were a clock. After every second, the clock resets and displays the new time.

\033c would have worked fine if Step 1-3 weren't there. But, they are, and the only way I can think of is to print all the data again.

It works, but it is not the most performant code. So, is there any way I can clear Step 4's output, and then reprint it with the changes?

Note: The last line of the terminal is not necessarily the last line of the program.



Related Questions





Does "DOS" have a shell?

Updated June 11, 2015 14:00 PM