Skip to content
Browse files

[dist] First commit

  • Loading branch information...
1 parent 9b0f149 commit 13073a39e8df731c43c0031450fa5bbe6a4b5a62 @Marak committed Oct 22, 2011
View
3 .gitignore
@@ -1 +1,2 @@
-.DS_Store
+.DS_Store
+node_modules/
View
199 node_modules/charm/README.markdown
@@ -1,199 +0,0 @@
-charm
-=====
-
-Use
-[ansi terminal characters](http://www.termsys.demon.co.uk/vtansi.htm)
-to write colors and cursor positions.
-
-![me lucky charms](http://substack.net/images/charms.png)
-
-example
-=======
-
-lucky
------
-
-````javascript
-var charm = require('charm')(process);
-charm.reset();
-
-var colors = [ 'red', 'cyan', 'yellow', 'green', 'blue' ];
-var text = 'Always after me lucky charms.';
-
-var offset = 0;
-var iv = setInterval(function () {
- var y = 0, dy = 1;
- for (var i = 0; i < 40; i++) {
- var color = colors[(i + offset) % colors.length];
- var c = text[(i + offset) % text.length];
- charm
- .move(1, dy)
- .foreground(color)
- .write(c)
- ;
- y += dy;
- if (y <= 0 || y >= 5) dy *= -1;
- }
- charm.position(0, 1);
- offset ++;
-}, 150);
-
-charm.on('data', function (buf) {
- if (buf[0] === 3) {
- clearInterval(iv);
- charm.destroy();
- }
-});
-````
-
-events
-======
-
-Charm objects pass along the data events from their input stream except for
-events generated from querying the terminal device.
-
-Because charm puts stdin into raw mode, charm emits two special events: "^C" and
-"^D" when the user types those combos. It's super convenient with these events
-to do:
-
-````javascript
-charm.on('^C', process.exit)
-````
-
-methods
-=======
-
-var charm = require('charm')(param or stream, ...)
---------------------------------------------------
-
-Create a new `charm` given a `param` with `stdout` and `stdin` streams, such as
-`process` or by passing the streams in themselves separately as parameters.
-
-Protip: you can pass in an http response object as an output stream and it will
-just work™.
-
-charm.reset()
--------------
-
-Reset the entire screen, like the /usr/bin/reset command.
-
-charm.destroy()
----------------
-
-Destroy the input stream.
-
-charm.write(msg)
-----------------
-
-Pass along `msg` to the output stream.
-
-charm.position(x, y) or charm.position(cb)
-------------------------------------------
-
-Set the cursor position to the absolute coordinates `x, y` or query the position
-and get the response as `cb(x, y)`.
-
-charm.move(x, y)
-----------------
-
-Move the cursor position by the relative coordinates `x, y`.
-
-charm.up(y)
------------
-
-Move the cursor up by `y` rows.
-
-charm.down(y)
--------------
-
-Move the cursor down by `y` rows.
-
-charm.left(x)
--------------
-
-Move the cursor left by `x` columns.
-
-charm.right(x)
--------------
-
-Move the cursor right by `x` columns.
-
-charm.push(withAttributes=false)
---------------------------------
-
-Push the cursor state and optionally the attribute state.
-
-charm.pop(withAttributes=false)
--------------------------------
-
-Pop the cursor state and optionally the attribute state.
-
-charm.erase(s)
---------------
-
-Erase a region defined by the string `s`.
-
-`s` can be:
-
-* end - erase from the cursor to the end of the line
-* start - erase from the cursor to the start of the line
-* line - erase the current line
-* down - erase everything below the current line
-* up - erase everything above the current line
-* screen - erase the entire screen
-
-charm.display(attr)
--------------------
-
-Set the display mode with the string `attr`.
-
-`attr` can be:
-
-* reset
-* bright
-* dim
-* underscore
-* blink
-* reverse
-* hidden
-
-charm.foreground(color)
------------------------
-
-Set the foreground color with the string `color`, which can be:
-
-* red
-* yellow
-* green
-* blue
-* cyan
-* magenta
-* black
-* white
-
-
-charm.background(color)
------------------------
-
-Set the background color with the string `color`, which can be:
-
-* red
-* yellow
-* green
-* blue
-* cyan
-* magenta
-* black
-* white
-
-charm.cursor(visible)
----------------------
-
-Set the cursor visibility with a boolean `visible`.
-
-install
-=======
-
-With [npm](http://npmjs.org) do:
-
- npm install charm
View
10 node_modules/charm/example/column.js
@@ -1,10 +0,0 @@
-var charm = require('charm')(process);
-
-charm
- .column(16)
- .write('beep')
- .down()
- .column(32)
- .write('boop\n')
- .destroy()
-;
View
22 node_modules/charm/example/cursor.js
@@ -1,22 +0,0 @@
-var charm = require('charm')(process);
-
-charm.position(5, 10);
-
-charm.position(function (x, y) {
- console.dir([ x, y ]);
-
- charm.move(7,2);
- charm.push();
- process.stdout.write('lul');
-
- charm.left(3).up(1).foreground('magenta');
- process.stdout.write('v');
- charm.left(1).up(1).display('reset');
- process.stdout.write('|');
-
- charm.down(3);
- charm.pop().background('blue');
- process.stdout.write('popped\npow');
- charm.display('reset').erase('line');
- charm.destroy();
-});
View
35 node_modules/charm/example/http_spin.js
@@ -1,35 +0,0 @@
-var http = require('http');
-var charmer = require('charm');
-
-http.createServer(function (req, res) {
- res.setHeader('content-type', 'text/ansi');
-
- var charm = charmer(res);
- charm.reset();
-
- var radius = 10;
- var theta = 0;
- var points = [];
-
- var iv = setInterval(function () {
- var x = 2 + (radius + Math.cos(theta) * radius) * 2;
- var y = 2 + radius + Math.sin(theta) * radius;
-
- points.unshift([ x, y ]);
- var colors = [ 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta' ];
-
- points.forEach(function (p, i) {
- charm.position(p[0], p[1]);
- var c = colors[Math.floor(i / 12)];
- charm.background(c).write(' ')
- });
- points = points.slice(0, 12 * colors.length - 1);
-
- theta += Math.PI / 40;
- }, 50);
-
- req.connection.on('end', function () {
- clearInterval(iv);
- charm.destroy();
- });
-}).listen(8081);
View
30 node_modules/charm/example/lucky.js
@@ -1,30 +0,0 @@
-var charm = require('charm')(process);
-charm.reset();
-
-var colors = [ 'red', 'cyan', 'yellow', 'green', 'blue' ];
-var text = 'Always after me lucky charms.';
-
-var offset = 0;
-var iv = setInterval(function () {
- var y = 0, dy = 1;
- for (var i = 0; i < 40; i++) {
- var color = colors[(i + offset) % colors.length];
- var c = text[(i + offset) % text.length];
- charm
- .move(1, dy)
- .foreground(color)
- .write(c)
- ;
- y += dy;
- if (y <= 0 || y >= 5) dy *= -1;
- }
- charm.position(0, 1);
- offset ++;
-}, 150);
-
-charm.on('data', function (buf) {
- if (buf[0] === 3) {
- clearInterval(iv);
- charm.destroy();
- }
-});
View
7 node_modules/charm/example/position.js
@@ -1,7 +0,0 @@
-var charm = require('charm')(process);
-
-charm.on('^C', process.exit);
-
-charm.position(function (x, y) {
- console.log('(%d, %d)', x, y);
-});
View
23 node_modules/charm/example/spin.js
@@ -1,23 +0,0 @@
-var charm = require('charm')(process);
-charm.reset();
-
-var radius = 10;
-var theta = 0;
-var points = [];
-
-var iv = setInterval(function () {
- var x = 2 + (radius + Math.cos(theta) * radius) * 2;
- var y = 2 + radius + Math.sin(theta) * radius;
-
- points.unshift([ x, y ]);
- var colors = [ 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta' ];
-
- points.forEach(function (p, i) {
- charm.position(p[0], p[1]);
- var c = colors[Math.floor(i / 12)];
- charm.background(c).write(' ')
- });
- points = points.slice(0, 12 * colors.length - 1);
-
- theta += Math.PI / 40;
-}, 50);
View
267 node_modules/charm/index.js
@@ -1,267 +0,0 @@
-var tty = require('tty');
-var encode = require('./lib/encode');
-var EventEmitter = require('events').EventEmitter;
-
-var exports = module.exports = function () {
- var input = null;
- function setInput (s) {
- if (input) throw new Error('multiple inputs specified')
- else input = s
- }
-
- var output = null;
- function setOutput (s) {
- if (output) throw new Error('multiple outputs specified')
- else output = s
- }
-
- for (var i = 0; i < arguments.length; i++) {
- var arg = arguments[i];
- if (!arg) continue;
- if (arg.readable) setInput(arg)
- else if (arg.stdin || arg.input) setInput(arg.stdin || arg.input)
-
- if (arg.writable) setOutput(arg)
- else if (arg.stdout || arg.output) setOutput(arg.stdout || arg.output)
-
- }
-
- return new Charm(input, output);
-};
-
-var Charm = exports.Charm = function (input, output) {
- var self = this;
- self.input = input;
- self.output = output;
- self.pending = [];
-
- if (!output) {
- self.emit('error', new Error('output stream required'));
- }
-
- if (input === process.stdin) {
- tty.setRawMode(true);
- input.resume();
- }
-
- if (input) {
- input.on('data', function (buf) {
- if (self.pending.length) {
- var codes = extractCodes(buf);
- var matched = false;
-
- for (var i = 0; i < codes.length; i++) {
- for (var j = 0; j < self.pending.length; j++) {
- var cb = self.pending[j];
- if (cb(codes[i])) {
- matched = true;
- self.pending.splice(j, 1);
- break;
- }
- }
- }
-
- if (matched) return;
- }
-
- self.emit('data', buf)
-
- if (buf.length === 1) {
- if (buf[0] === 3) self.emit('^C');
- if (buf[0] === 4) self.emit('^D');
- }
- });
- }
-}
-
-Charm.prototype = new EventEmitter;
-
-Charm.prototype.destroy = function () {
- if (this.input) this.input.destroy()
-};
-
-Charm.prototype.write = function (msg) {
- this.output.write(msg);
- return this;
-};
-
-Charm.prototype.reset = function (cb) {
- this.write(encode('c'));
- return this;
-};
-
-Charm.prototype.position = function (x, y) {
- // get/set absolute coordinates
- if (typeof x === 'function') {
- var cb = x;
- this.pending.push(function (buf) {
- if (buf[0] === 27 && buf[1] === encode.ord('[')
- && buf[buf.length-1] === encode.ord('R')) {
- var pos = buf.toString()
- .slice(2,-1)
- .split(';')
- .map(Number)
- ;
- cb(pos[1], pos[0]);
- return true;
- }
- });
- this.write(encode('[6n'));
- }
- else {
- this.write(encode(
- '[' + Math.floor(y) + ';' + Math.floor(x) + 'f'
- ));
- }
- return this;
-};
-
-Charm.prototype.move = function (x, y) {
- // set relative coordinates
- var bufs = [];
-
- if (y < 0) this.up(-y)
- else if (y > 0) this.down(y)
-
- if (x > 0) this.right(x)
- else if (x < 0) this.left(-x)
-
- return this;
-};
-
-Charm.prototype.up = function (y) {
- if (y === undefined) y = 1;
- this.write(encode('[' + Math.floor(y) + 'A'));
- return this;
-};
-
-Charm.prototype.down = function (y) {
- if (y === undefined) y = 1;
- this.write(encode('[' + Math.floor(y) + 'B'));
- return this;
-};
-
-Charm.prototype.right = function (x) {
- if (x === undefined) x = 1;
- this.write(encode('[' + Math.floor(x) + 'C'));
- return this;
-};
-
-Charm.prototype.left = function (x) {
- if (x === undefined) x = 1;
- this.write(encode('[' + Math.floor(x) + 'D'));
- return this;
-};
-
-Charm.prototype.column = function (x) {
- this.write(encode('[' + Math.floor(x) + 'G'));
- return this;
-};
-
-Charm.prototype.push = function (withAttributes) {
- this.write(encode(withAttributes ? '7' : '[s'));
- return this;
-};
-
-Charm.prototype.pop = function (withAttributes) {
- this.write(encode(withAttributes ? '8' : '[u'));
- return this;
-};
-
-Charm.prototype.erase = function (s) {
- if (s === 'end' || s === '$') {
- this.write(encode('[K'));
- }
- else if (s === 'start' || s === '^') {
- this.write(encode('[1K'));
- }
- else if (s === 'line') {
- this.write(encode('[2K'));
- }
- else if (s === 'down') {
- this.write(encode('[J'));
- }
- else if (s === 'up') {
- this.write(encode('[1J'));
- }
- else if (s === 'screen') {
- this.write(encode('[1J'));
- }
- else {
- this.emit('error', new Error('Unknown erase type: ' + s));
- }
- return this;
-};
-
-Charm.prototype.display = function (attr) {
- var c = {
- reset : 0,
- bright : 1,
- dim : 2,
- underscore : 4,
- blink : 5,
- reverse : 7,
- hidden : 8
- }[attr];
- if (c === undefined) {
- this.emit('error', new Error('Unknown attribute: ' + attr));
- }
- this.write(encode('[' + c + 'm'));
- return this;
-};
-
-Charm.prototype.foreground = function (color) {
- var c = {
- black : 30,
- red : 31,
- green : 32,
- yellow : 33,
- blue : 34,
- magenta : 35,
- cyan : 36,
- white : 37
- }[color.toLowerCase()];
- if (!c) this.emit('error', new Error('Unknown color: ' + color));
-
- this.write(encode('[' + c + 'm'));
- return this;
-};
-
-Charm.prototype.background = function (color) {
- var c = {
- black : 40,
- red : 41,
- green : 42,
- yellow : 43,
- blue : 44,
- magenta : 45,
- cyan : 46,
- white : 47
- }[color.toLowerCase()];
- if (!c) this.emit('error', new Error('Unknown color: ' + color));
-
- this.write(encode('[' + c + 'm'));
- return this;
-};
-
-Charm.prototype.cursor = function (visible) {
- this.write(encode(visible ? '[?25h' : '[?25l'));
- return this;
-};
-
-var extractCodes = exports.extractCodes = function (buf) {
- var codes = [];
- var start = -1;
-
- for (var i = 0; i < buf.length; i++) {
- if (buf[i] === 27) {
- if (start >= 0) codes.push(buf.slice(start, i));
- start = i;
- }
- else if (start >= 0 && i === buf.length - 1) {
- codes.push(buf.slice(start));
- }
- }
-
- return codes;
-}
View
18 node_modules/charm/lib/encode.js
@@ -1,18 +0,0 @@
-var encode = module.exports = function (xs) {
- function bytes (s) {
- if (typeof s === 'string') {
- return s.split('').map(ord);
- }
- else if (Array.isArray(s)) {
- return s.reduce(function (acc, c) {
- return acc.concat(bytes(c));
- }, []);
- }
- }
-
- return new Buffer([ 0x1b ].concat(bytes(xs)));
-};
-
-var ord = encode.ord = function ord (c) {
- return c.charCodeAt(0)
-};
View
32 node_modules/charm/package.json
@@ -1,32 +0,0 @@
-{
- "name" : "charm",
- "version" : "0.0.5",
- "description" : "ansi control sequences for terminal cursor hopping and colors",
- "main" : "index.js",
- "directories" : {
- "lib" : ".",
- "example" : "example",
- "test" : "test"
- },
- "repository" : {
- "type" : "git",
- "url" : "http://github.com/substack/node-charm.git"
- },
- "keywords" : [
- "terminal",
- "ansi",
- "cursor",
- "color",
- "console",
- "control",
- "escape",
- "sequence"
- ],
- "author" : {
- "name" : "James Halliday",
- "email" : "mail@substack.net",
- "url" : "http://substack.net"
- },
- "license" : "MIT/X11",
- "engine" : { "node" : ">=0.4" }
-}
View
106 node_modules/multimeter/README.markdown
@@ -1,106 +0,0 @@
-multimeter
-==========
-
-Control multiple ANSI progress bars on the terminal.
-
-![multibar example output](http://substack.net/images/screenshots/multibar.png)
-
-![multimeter](http://substack.net/images/multimeter.png)
-
-example
-=======
-
-````javascript
-var multimeter = require('multimeter');
-var multi = multimeter(process);
-
-multi.drop(function (bar) {
- var iv = setInterval(function () {
- var p = bar.percent();
- bar.percent(p + 1);
-
- if (p >= 100) clearInterval(iv);
- }, 25);
-});
-````
-
-methods
-=======
-
-var multimeter = require('multimeter');
-
-var multi = multimeter(stream, ...)
------------------------------------
-
-Create a new multimeter handle on the supplied stream/process objects, which
-will be passed directly to [charm](https://github.com/substack/node-charm).
-
-If you pass in a charm object that will be used instead of creating a new one.
-
-var bar = multi(x, y, params)
------------------------------
-
-Create a new progress bar at `(x,y)` with `params` which default to:
-
-* width : 10
-* before : '['
-* after : '] '
-* solid : { background : 'blue', foreground : 'white', text : '|' }
-* empty : { background : null, foreground : null, text : ' ' }
-
-If `y` is negative or `'-0'` it will be treated as a relative coordinate.
-
-var bar = multi.rel(x, y, params)
----------------------------------
-
-Create a new progress bar at an absolute `x` and relative `y` coordinate with
-respect to the present `multi.offset`.
-
-multi.drop(params, cb)
-----------------------
-
-Create a new progress bar at the present cursor location. The `bar` object will
-be passed to `cb(bar)` once the cursor location has been determined.
-
-multi.on(...), multi.removeListener(...), multi.destroy(...), multi.write(...)
-------------------------------------------------------------------------------
-
-Call event emitter functions on the underlying `charm` object.
-
-multi.offset
-------------
-
-This getter/setter controls the positioning for relative progress bars.
-
-Increment this value whenever you write a newline to the stream to prevent the
-pending progress bars from drifting down from their original positions.
-
-bar.percent(p, msg=p + ' %')
-----------------------------
-
-Update the progress bar to `p` percent, a value between 0 and 100, inclusive.
-
-The text to the right of the progress bar will be set to `msg`.
-
-bar.ratio(n, d, msg=n + ' / ' + d)
-----------------------------------
-
-Update the progress bar with a ratio, `n/d`.
-
-The text to the right of the progress bar will be set to `msg`.
-
-attributes
-==========
-
-multi.charm
------------
-
-The [charm](https://github.com/substack/node-charm) object used internally to
-draw the progress bars.
-
-install
-=======
-
-With [npm](http://npmjs.org) do:
-
- npm install multimeter
View
23 node_modules/multimeter/example/drop.js
@@ -1,23 +0,0 @@
-var multimeter = require('multimeter');
-var multi = multimeter(process);
-
-multi.on('^C', function () {
- multi.charm.cursor(true);
- multi.write('\n').destroy();
-
- process.exit();
-});
-multi.charm.cursor(false);
-
-multi.drop(function (bar) {
- var iv = setInterval(function () {
- var p = bar.percent();
- bar.percent(p + 1);
- if (p >= 100) {
- clearInterval(iv);
-
- multi.charm.cursor(true);
- multi.write('\n').destroy();
- }
- }, 25);
-});
View
47 node_modules/multimeter/example/multibar.js
@@ -1,47 +0,0 @@
-var multimeter = require('multimeter');
-
-var multi = multimeter(process);
-multi.on('^C', process.exit);
-multi.charm.reset();
-
-var bars = [];
-var progress = [];
-var deltas = [];
-
-multi.write('Progress:\n\n');
-
-for (var i = 0; i < 5; i++) {
- var s = 'ABCDE'[i] + ': \n';
- multi.write(s);
-
- var bar = multi(s.length, i + 3, {
- width : 20,
- solid : {
- text : '|',
- foreground : 'white',
- background : 'blue'
- },
- empty : { text : ' ' },
- });
- bars.push(bar);
-
- deltas[i] = 1 + Math.random() * 9;
- progress.push(0);
-}
-
-multi.write('\nbeep boop\n');
-
-var pending = progress.length;
-var iv = setInterval(function () {
- progress.forEach(function (p, i) {
- progress[i] += Math.random() * deltas[i];
- bars[i].percent(progress[i]);
- if (p < 100 && progress[i] >= 100) pending --;
- if (pending === 0) {
- multi.write('\nAll done.\n');
- multi.destroy();
- clearInterval(iv);
- pending --;
- }
- });
-}, 100);
View
52 node_modules/multimeter/example/multirel.js
@@ -1,52 +0,0 @@
-var multimeter = require('multimeter');
-
-var multi = multimeter(process);
-multi.on('^C', process.exit);
-
-var bars = [];
-var progress = [];
-var deltas = [];
-
-multi.write('Progress:\n\n');
-
-for (var i = 0; i < 5; i++) {
- var s = 'ABCDE'[i] + ': \n';
- multi.write(s);
-
- var bar = multi.rel(4, i, {
- width : 20,
- solid : {
- text : '|',
- foreground : 'white',
- background : 'blue'
- },
- empty : { text : ' ' },
- });
- bars.push(bar);
-
- deltas[i] = 1 + Math.random() * 9;
- progress.push(0);
-}
-
-multi.offset += 2;
-multi.write('\nbeep');
-
-setTimeout(function () {
- multi.offset ++;
- multi.write('\n boop');
-}, 2000);
-
-var pending = progress.length;
-var iv = setInterval(function () {
- progress.forEach(function (p, i) {
- progress[i] += Math.random() * deltas[i];
- bars[i].percent(progress[i]);
- if (p < 100 && progress[i] >= 100) pending --;
- if (pending === 0) {
- multi.write('\nAll done.\n');
- multi.destroy();
- clearInterval(iv);
- pending --;
- }
- });
-}, 100);
View
11 node_modules/multimeter/example/single.js
@@ -1,11 +0,0 @@
-var multimeter = require('multimeter');
-var multi = multimeter(process);
-
-multi.drop(function (bar) {
- var iv = setInterval(function () {
- var p = bar.percent();
- bar.percent(p + 1);
-
- if (p >= 100) clearInterval(iv);
- }, 25);
-});
View
37 node_modules/multimeter/example/sum.js
@@ -1,37 +0,0 @@
-var multimeter = require('multimeter');
-
-var multi = multimeter(process);
-var charm = multi.charm;
-charm.on('^C', process.exit);
-charm.reset();
-
-var xs = [];
-for (var i = 0; i < 100; i++) xs.push(i);
-
-console.log('Calculating the sum of [0..100]:\n');
-charm.write(' ');
-
-multi.drop(function (bar) {
- bar.percent(0);
-
- charm.write('\n\nResult: ');
- charm.position(function (x, y) {
- var sum = 0;
- var iv = setInterval(function () {
- sum += xs.shift();
-
- bar.percent(100 - xs.length);
-
- charm
- .position(x, y)
- .erase('end')
- .write(sum.toString())
- ;
-
- if (xs.length === 0) {
- clearInterval(iv);
- multi.destroy();
- }
- }, 50);
- });
-});
View
55 node_modules/multimeter/example/web_multibar.js
@@ -1,55 +0,0 @@
-var http = require('http');
-var multimeter = require('multimeter');
-
-http.createServer(function (req, res) {
- res.setHeader('content-type', 'application/octet-stream');
-
- var multi = multimeter(res);
- multi.charm.on('^C', process.exit);
- multi.charm.reset();
-
- var bars = [];
- var progress = [];
- var deltas = [];
-
- for (var i = 0; i < 5; i++) {
- var s = 'ABCDE'[i] + ': \n';
- multi.write(s);
-
- var bar = multi(s.length, i + 1, {
- width : 20,
- solid : {
- text : '|',
- foreground : 'white',
- background : 'blue'
- },
- empty : { text : ' ' },
- });
- bars.push(bar);
-
- deltas[i] = 1 + Math.random() * 9;
- progress.push(0);
- }
-
- multi.write('\nbeep boop\n');
-
- var pending = progress.length;
- var iv = setInterval(function () {
- progress.forEach(function (p, i) {
- progress[i] += Math.random() * deltas[i];
- bars[i].percent(progress[i]);
- if (p < 100 && progress[i] >= 100) pending --;
- if (pending === 0) {
- multi.write('\nAll done.\n');
- res.end();
- }
- });
- }, 100);
-
- res.connection.on('end', function () {
- multi.destroy();
- clearInterval(iv);
- });
-}).listen(8080);
-
-console.log('curl -N localhost:8080');
View
60 node_modules/multimeter/example/web_multirel.js
@@ -1,60 +0,0 @@
-var http = require('http');
-var multimeter = require('multimeter');
-
-http.createServer(function (req, res) {
- res.setHeader('content-type', 'application/octet-stream');
-
- var multi = multimeter(res);
- multi.charm.on('^C', process.exit);
-
- var bars = [];
- var progress = [];
- var deltas = [];
-
- for (var i = 0; i < 5; i++) {
- var s = 'ABCDE'[i] + ': \n';
- multi.write(s);
-
- var bar = multi.rel(4, i, {
- width : 20,
- solid : {
- text : '|',
- foreground : 'white',
- background : 'blue'
- },
- empty : { text : ' ' },
- });
- bars.push(bar);
-
- deltas[i] = 5 + Math.random() * 10;
- progress.push(0);
- }
-
- multi.offset += 2;
- multi.write('\nbeep');
-
- setTimeout(function () {
- multi.offset ++;
- multi.write('\n boop');
- }, 1000);
-
- var pending = progress.length;
- var iv = setInterval(function () {
- progress.forEach(function (p, i) {
- progress[i] += Math.random() * deltas[i];
- bars[i].percent(progress[i]);
- if (p < 100 && progress[i] >= 100) pending --;
- if (pending === 0) {
- multi.write('\nAll done.\n');
- res.end();
- }
- });
- }, 100);
-
- res.connection.on('end', function () {
- multi.destroy();
- clearInterval(iv);
- });
-}).listen(8080);
-
-console.log('curl -N localhost:8080');
View
45 node_modules/multimeter/example/web_sum.js
@@ -1,45 +0,0 @@
-var http = require('http');
-var multimeter = require('multimeter');
-
-http.createServer(function (req, res) {
- var multi = multimeter(res);
- var charm = multi.charm;
-
- var xs = [];
- for (var i = 0; i < 100; i++) xs.push(i);
-
- charm.reset()
- .write('Calculating the sum of [0..100]:\n\n')
- ;
-
- var bar = multi(4, 3, { width : 20 });
- bar.percent(0);
-
- var sum = 0;
- charm.write('\n\nResult: ' + sum);
-
- var iv = setInterval(function () {
- var x = xs.shift();
- bar.percent(100 - xs.length);
-
- charm
- .left(sum.toString().length)
- .erase('end')
- ;
- sum += x;
-
- charm.write(sum.toString());
-
- if (xs.length === 0) {
- charm.write('\n');
- res.end();
- }
- }, 50);
-
- res.connection.on('end', function () {
- multi.destroy();
- clearInterval(iv);
- });
-}).listen(8081);
-
-console.log('curl -N localhost:8081');
View
75 node_modules/multimeter/index.js
@@ -1,75 +0,0 @@
-var charmer = require('charm');
-var Bar = require('./lib/bar');
-
-var exports = module.exports = function (c) {
- if (c instanceof charmer.Charm) {
- var charm = c;
- }
- else {
- var charm = charmer.apply(null, arguments);
- charm.on('^C', function () {
- charm.destroy();
- });
- }
-
- var multi = function (x, y, params) {
- if (typeof x === 'object') {
- params = x;
- x = params.x;
- y = params.y;
- }
- if (!params) params = {};
-
- if (x === undefined) x = '+0';
- if (y === undefined) y = '+0';
-
- var bar = new Bar(charm, x, y, params);
- multi.bars.push(bar);
- bar.offset = multi.offset;
- multi.on('offset', function (o) {
- bar.offset = o;
- });
- return bar;
- };
- multi.bars = [];
-
- multi.rel = function (x, y, params) {
- return multi(x, '-' + y, params);
- };
-
- multi.drop = function (params, cb) {
- if (!cb) { cb = params; params = {} }
-
- charm.position(function (x, y) {
- var bar = new Bar(charm, x, y, params);
- multi.bars.push(bar);
- multi.on('offset', function (o) {
- bar.offset = o;
- });
- cb(bar);
- });
- };
-
- multi.charm = charm;
- multi.destroy = charm.destroy.bind(charm);
-
- multi.on = charm.on.bind(charm);
- multi.emit = charm.emit.bind(charm);
- multi.removeListener = charm.removeListener.bind(charm);
- multi.write = charm.write.bind(charm);
-
- (function () {
- var offset = 0;
- Object.defineProperty(multi, 'offset', {
- set : function (o) {
- offset = o;
- multi.emit('offset', o);
- },
- get : function () {
- return offset;
- }
- });
- })();
-
- return multi;
-};
View
111 node_modules/multimeter/lib/bar.js
@@ -1,111 +0,0 @@
-var Bar = module.exports = function (charm, x, y, params) {
- this.charm = charm;
- this.x = x;
- this.y = y;
- this.width = params.width || 10;
- this.offset = params.offset || 0;
-
- this.before = params.before || '[';
- this.after = params.after || '] ';
-
- this.solid = params.solid || {
- background : 'blue',
- foreground : 'white',
- text : '|'
- };
-
- this.empty = params.empty || {
- background : null,
- foreground : null,
- text : ' '
- };
-
- this.progress = {
- percent : 0,
- ratio : 0
- };
-}
-
-Bar.prototype.draw = function (bars, msg) {
- bars = Math.floor(bars);
- this.charm.push(true);
-
- if (this.y.toString().match(/^[+-]/)) {
- if (this.y.toString().match(/^-/)) {
- this.charm.up(-this.y + this.offset);
- }
- else if (this.y.toString().match(/^\+/)) {
- this.charm.down(+this.y - this.offset);
- }
- this.charm.column(+this.x);
- }
- else {
- this.charm.position(this.x, this.y);
- }
-
- this.charm.write(this.before);
-
- if (this.solid.background) {
- this.charm.background(this.solid.background);
- }
- if (this.solid.foreground) {
- this.charm.foreground(this.solid.foreground);
- }
-
- this.charm
- .write(Array(bars + 1).join(this.solid.text))
- .display('reset')
- ;
-
- if (this.empty.background) {
- this.charm.background(this.empty.background);
- }
- if (this.empty.foreground) {
- this.charm.foreground(this.empty.foreground);
- }
-
- this.charm
- .write(Array(this.width - bars + 1).join(this.empty.text))
- .write(this.after + msg)
- ;
-
- this.charm.pop(true);
-
- return this;
-};
-
-Bar.prototype.percent = function (p, msg) {
- if (p === undefined) {
- return this.progress.percent;
- }
- else {
- p = Math.min(100, p);
- this.progress.percent = p;
- this.progress.ratio = [ p, 100 ];
-
- this.draw(
- this.width * p / 100,
- msg || (Math.floor(p) + ' %')
- );
-
- return this;
- }
-};
-
-Bar.prototype.ratio = function (n, d, msg) {
- if (n === undefined && d === undefined) {
- return this.progress.ratio;
- }
- else {
- var f = n / d;
- this.progress.ratio = [ n, d ];
- this.progress.percent = f * 100;
-
- this.draw(
- this.width * f,
- msg || (n + ' / ' + d)
- );
-
- return this;
- }
-};
View
34 node_modules/multimeter/package.json
@@ -1,34 +0,0 @@
-{
- "name" : "multimeter",
- "version" : "0.1.0",
- "description" : "render multiple progress bars at once on the terminal",
- "main" : "index.js",
- "directories" : {
- "lib" : ".",
- "example" : "example",
- "test" : "test"
- },
- "dependencies" : {
- "charm" : ">=0.0.5 <0.1"
- },
- "repository" : {
- "type" : "git",
- "url" : "http://github.com/substack/node-multimeter.git"
- },
- "keywords" : [
- "progress",
- "bar",
- "status",
- "meter",
- "terminal",
- "console",
- "ansi"
- ],
- "author" : {
- "name" : "James Halliday",
- "email" : "mail@substack.net",
- "url" : "http://substack.net"
- },
- "license" : "MIT/X11",
- "engine" : { "node" : ">=0.4" }
-}

0 comments on commit 13073a3

Please sign in to comment.
Something went wrong with that request. Please try again.