0

So when you console.log you're appending lines to stdout. I understand that much, but how do programs like top print to the console a continually refreshed view of data and then wipe that data when you kill it?

You can see when I kill top its data is no longer displayed. I can't scroll in my terminal window or anything to see it either, like most other scripts and programs I use.

How can I do this in node? I want to display some data and continually refresh it in place until the script is killed.

CatDadCode
  • 58,507
  • 61
  • 212
  • 318
  • 2
    Try [blessed-contrib](https://github.com/yaronn/blessed-contrib) or [clui](https://github.com/nathanpeck/clui#gaugevalue-maxvalue-gaugewidth-dangerzone-suffix). I haven't myself but it looks like they could.. – laggingreflex Feb 05 '15 at 08:27

2 Answers2

1

The way to do it is with ANSII Escape Sequences. It's tedious to do manually so I went with a library called blessed. It allows you to create terminal user interfaces pretty easily. It takes care of doing all the annoying low-level ANSII escape sequences for you and just gives you controls you can instantiate and configure.

CatDadCode
  • 58,507
  • 61
  • 212
  • 318
0

Can't you do CLS and then resend new data to the screen ?

Rohan Sharma
  • 1,416
  • 2
  • 14
  • 19
  • That would clear my entire terminal buffer. Notice when I kill *top* it returns me to my normal prompt and I can see my terminal history, just not the output from *top*. Also notice that while *top* is running I can't see my terminal history. – CatDadCode Feb 05 '15 at 03:26