Last active
August 29, 2015 14:07
-
-
Save ben-bradley/282674a12cefd5feb9bc to your computer and use it in GitHub Desktop.
ASCII charts in the command line with Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html | |
var chart = require('ascii-chart'), | |
_ = require('lodash'); | |
var data = []; | |
var out = process.stdout; | |
out.write('\033[2J'); // clear the screen | |
setInterval(function () { | |
var datum = _.random(0, 100); | |
data.push(datum); | |
data = _.last(data, 40); | |
out.write('\033[0;0H'); // set the cursor to 0;0 | |
datum = (datum < 10) ? ' ' + datum : (datum < 99) ? ' ' + datum : datum; | |
console.log('Current: ' + datum); | |
out.write(chart(data, { | |
width: 80, | |
height: 20 | |
})); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment