How to redirect stdout to bliss?

In short: I want to create a CLI for the development daemon. Daemon displays various information in stdout, and I want to pass this information to the user in a screen area in a scrollable way. I struggle to be happy. A simple prototype below that buffers stdout, so the information never completes.

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(); } status('TEST'); var spawn = require('child_process').spawn; yes = spawn('yes', ['it is']); ls.stdout.on('data', function (data) { log(data.toString()); }); ls.stderr.on('data', function (data) { log(data.toString()); }); 
+7
command-line-interface
source share
1 answer

Line

 var screen = blessed.screen() 

Accepts parameters to change where the input comes from and where the output comes from. Logically, they are called input and output:

 var screen = blessed.screen({ input: some_input_stream, output: some_output_stream }) 

So, you simply insert the recordable (or duplex) stream into the output parameter. Then you can output the output anywhere.

0
source share

All Articles