nodejs - how to keep an status at top of stdout

node.js

Solution

Here's an example using blessed:

var blessed = require('blessed');

var screen = blessed.screen(),
    body = blessed.box({
      top: 1,
      left: 0,
      width: '100%',
      height: '99%'
    }),
    statusbar = blessed.box({
      top: 0,
      left: 0,
      width: '100%',
      height: 1,
      style: {
        fg: 'white',
        bg: 'blue'
      }
    });

screen.append(statusbar);
screen.append(body);

screen.key(['escape', 'q', 'C-c'], function(ch, key) {
  return process.exit(0);
});

function status(text) { statusbar.setContent(text); screen.render(); }
function log(text) { body.insertLine(0, text); screen.render(); }

var c = 1;
setInterval(function() {
  status((new Date()).toISOString());
  log('This is line #' + (c++));
}, 100);

Here's a simpler example that has almost the same effect (the status bar doesn't fill in extra space with background color):

var screen = blessed.screen(),
    body = blessed.box({
      top: 0,
      left: 0,
      width: '100%',
      height: '100%',
      tags: true
    });

screen.append(body);

screen.key(['escape', 'q', 'C-c'], function(ch, key) {
  return process.exit(0);
});

function status(text) {
  body.setLine(0, '{blue-bg}' + text + '{/blue-bg}');
  screen.render();
}
function log(text) {
  body.insertLine(1, text);
  screen.render();
}

var c = 1;
setInterval(function() {
  status((new Date()).toISOString());
  log('This is line #' + (c++));
}, 100);

Problem

I'm trying to output something like these: ``` counter is: 10 <= fixed line and auto updating console.logs, etc... <= other console.logs, errors, defaul outputs console.logs, etc... console.logs, etc... console.logs, etc... ``` Is this possible? I have tried with process.stdout.write() but it is not working. ``` var counter = 0; setInterval(function(){ counter++; process.stdout.write("counter is " + counter + " \r"); }, 500); setInterval(function(){ console.log('some output'); }, 1500); ```

Original source