Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

renames files and folders following standard practice

  • Loading branch information...
commit 6b482b7456ce65afe39ec69b7aee216272d87273 1 parent 3143543
Francisco Giordano authored December 07, 2012
0  main.js → example/main.js
File renamed without changes
0  life.js → index.js
File renamed without changes
0  grid.js → lib/grid.js
File renamed without changes
206  node_modules/charm/README.markdown
Source Rendered
... ...
@@ -0,0 +1,206 @@
  1
+charm
  2
+=====
  3
+
  4
+Use
  5
+[ansi terminal characters](http://www.termsys.demon.co.uk/vtansi.htm)
  6
+to write colors and cursor positions.
  7
+
  8
+![me lucky charms](http://substack.net/images/charms.png)
  9
+
  10
+example
  11
+=======
  12
+
  13
+lucky
  14
+-----
  15
+
  16
+````javascript
  17
+var charm = require('charm')();
  18
+charm.pipe(process.stdout);
  19
+charm.reset();
  20
+
  21
+var colors = [ 'red', 'cyan', 'yellow', 'green', 'blue' ];
  22
+var text = 'Always after me lucky charms.';
  23
+
  24
+var offset = 0;
  25
+var iv = setInterval(function () {
  26
+    var y = 0, dy = 1;
  27
+    for (var i = 0; i < 40; i++) {
  28
+        var color = colors[(i + offset) % colors.length];
  29
+        var c = text[(i + offset) % text.length];
  30
+        charm
  31
+            .move(1, dy)
  32
+            .foreground(color)
  33
+            .write(c)
  34
+        ;
  35
+        y += dy;
  36
+        if (y <= 0 || y >= 5) dy *= -1;
  37
+    }
  38
+    charm.position(0, 1);
  39
+    offset ++;
  40
+}, 150);
  41
+````
  42
+
  43
+events
  44
+======
  45
+
  46
+Charm objects pass along the data events from their input stream except for
  47
+events generated from querying the terminal device.
  48
+
  49
+Because charm puts stdin into raw mode, charm emits two special events: "^C" and
  50
+"^D" when the user types those combos. It's super convenient with these events
  51
+to do:
  52
+
  53
+````javascript
  54
+charm.on('^C', process.exit)
  55
+````
  56
+
  57
+methods
  58
+=======
  59
+
  60
+var charm = require('charm')(param or stream, ...)
  61
+--------------------------------------------------
  62
+
  63
+Create a new readable/writable `charm` stream.
  64
+
  65
+You can pass in readable or writable streams as parameters and they will be
  66
+piped to or from accordingly. You can also pass `process` in which case
  67
+`process.stdin` and `process.stdout` will be used.
  68
+
  69
+You can `pipe()` to and from the `charm` object you get back.
  70
+
  71
+charm.reset()
  72
+-------------
  73
+
  74
+Reset the entire screen, like the /usr/bin/reset command.
  75
+
  76
+charm.destroy(), charm.end()
  77
+----------------------------
  78
+
  79
+Emit an `"end"` event downstream.
  80
+
  81
+charm.write(msg)
  82
+----------------
  83
+
  84
+Pass along `msg` to the output stream.
  85
+
  86
+charm.position(x, y)
  87
+--------------------
  88
+
  89
+Set the cursor position to the absolute coordinates `x, y`.
  90
+
  91
+charm.position(cb)
  92
+------------------
  93
+
  94
+Query the absolute cursor position from the input stream through the output
  95
+stream (the shell does this automatically) and get the response back as
  96
+`cb(x, y)`.
  97
+
  98
+charm.move(x, y)
  99
+----------------
  100
+
  101
+Move the cursor position by the relative coordinates `x, y`.
  102
+
  103
+charm.up(y)
  104
+-----------
  105
+
  106
+Move the cursor up by `y` rows.
  107
+
  108
+charm.down(y)
  109
+-------------
  110
+
  111
+Move the cursor down by `y` rows.
  112
+
  113
+charm.left(x)
  114
+-------------
  115
+
  116
+Move the cursor left by `x` columns.
  117
+
  118
+charm.right(x)
  119
+--------------
  120
+
  121
+Move the cursor right by `x` columns.
  122
+
  123
+charm.push(withAttributes=false)
  124
+--------------------------------
  125
+
  126
+Push the cursor state and optionally the attribute state.
  127
+
  128
+charm.pop(withAttributes=false)
  129
+-------------------------------
  130
+
  131
+Pop the cursor state and optionally the attribute state.
  132
+
  133
+charm.erase(s)
  134
+--------------
  135
+
  136
+Erase a region defined by the string `s`.
  137
+
  138
+`s` can be:
  139
+
  140
+* end - erase from the cursor to the end of the line
  141
+* start - erase from the cursor to the start of the line
  142
+* line - erase the current line
  143
+* down - erase everything below the current line
  144
+* up - erase everything above the current line
  145
+* screen - erase the entire screen
  146
+
  147
+charm.display(attr)
  148
+-------------------
  149
+
  150
+Set the display mode with the string `attr`.
  151
+
  152
+`attr` can be:
  153
+
  154
+* reset
  155
+* bright
  156
+* dim
  157
+* underscore
  158
+* blink
  159
+* reverse
  160
+* hidden
  161
+
  162
+charm.foreground(color)
  163
+-----------------------
  164
+
  165
+Set the foreground color with the string `color`, which can be:
  166
+
  167
+* red
  168
+* yellow
  169
+* green
  170
+* blue
  171
+* cyan
  172
+* magenta
  173
+* black
  174
+* white
  175
+
  176
+or `color` can be an integer from 0 to 255, inclusive.
  177
+
  178
+charm.background(color)
  179
+-----------------------
  180
+
  181
+Set the background color with the string `color`, which can be:
  182
+
  183
+* red
  184
+* yellow
  185
+* green
  186
+* blue
  187
+* cyan
  188
+* magenta
  189
+* black
  190
+* white
  191
+
  192
+or `color` can be an integer from 0 to 255, inclusive.
  193
+
  194
+charm.cursor(visible)
  195
+---------------------
  196
+
  197
+Set the cursor visibility with a boolean `visible`.
  198
+
  199
+install
  200
+=======
  201
+
  202
+With [npm](http://npmjs.org) do:
  203
+
  204
+```
  205
+npm install charm
  206
+```
17  node_modules/charm/example/256.js
... ...
@@ -0,0 +1,17 @@
  1
+var charm = require('../')(process);
  2
+
  3
+function exit () {
  4
+    charm.display('reset');
  5
+    process.exit();
  6
+}
  7
+charm.on('^C', exit);
  8
+
  9
+var ix = 0;
  10
+var iv = setInterval(function () {
  11
+    charm.background(ix++).write(' ');
  12
+    if (ix === 256) {
  13
+        clearInterval(iv);
  14
+        charm.write('\n');
  15
+        exit();
  16
+    }
  17
+}, 10);
11  node_modules/charm/example/column.js
... ...
@@ -0,0 +1,11 @@
  1
+var charm = require('../')();
  2
+charm.pipe(process.stdout);
  3
+
  4
+charm
  5
+    .column(16)
  6
+    .write('beep')
  7
+    .down()
  8
+    .column(32)
  9
+    .write('boop\n')
  10
+    .end()
  11
+;
22  node_modules/charm/example/cursor.js
... ...
@@ -0,0 +1,22 @@
  1
+var charm = require('../')(process);
  2
+
  3
+charm.position(5, 10);
  4
+
  5
+charm.position(function (x, y) {
  6
+    console.dir([ x, y ]);
  7
+    
  8
+    charm.move(7,2);
  9
+    charm.push();
  10
+    process.stdout.write('lul');
  11
+    
  12
+    charm.left(3).up(1).foreground('magenta');
  13
+    process.stdout.write('v');
  14
+    charm.left(1).up(1).display('reset');
  15
+    process.stdout.write('|');
  16
+    
  17
+    charm.down(3);
  18
+    charm.pop().background('blue');
  19
+    process.stdout.write('popped\npow');
  20
+    charm.display('reset').erase('line');
  21
+    charm.destroy();
  22
+});
36  node_modules/charm/example/http_spin.js
... ...
@@ -0,0 +1,36 @@
  1
+var http = require('http');
  2
+var charmer = require('../');
  3
+
  4
+http.createServer(function (req, res) {
  5
+    res.setHeader('content-type', 'text/ansi');
  6
+    
  7
+    var charm = charmer();
  8
+    charm.pipe(res);
  9
+    charm.reset();
  10
+    
  11
+    var radius = 10;
  12
+    var theta = 0;
  13
+    var points = [];
  14
+
  15
+    var iv = setInterval(function () {
  16
+        var x = 2 + (radius + Math.cos(theta) * radius) * 2;
  17
+        var y = 2 + radius + Math.sin(theta) * radius;
  18
+        
  19
+        points.unshift([ x, y ]);
  20
+        var colors = [ 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta' ];
  21
+        
  22
+        points.forEach(function (p, i) {
  23
+            charm.position(p[0], p[1]);
  24
+            var c = colors[Math.floor(i / 12)];
  25
+            charm.background(c).write(' ')
  26
+        });
  27
+        points = points.slice(0, 12 * colors.length - 1);
  28
+        
  29
+        theta += Math.PI / 40;
  30
+    }, 50);
  31
+    
  32
+    req.connection.on('end', function () {
  33
+        clearInterval(iv);
  34
+        charm.end();
  35
+    });
  36
+}).listen(8081);
24  node_modules/charm/example/lucky.js
... ...
@@ -0,0 +1,24 @@
  1
+var charm = require('../')();
  2
+charm.pipe(process.stdout);
  3
+charm.reset();
  4
+
  5
+var colors = [ 'red', 'cyan', 'yellow', 'green', 'blue' ];
  6
+var text = 'Always after me lucky charms.';
  7
+
  8
+var offset = 0;
  9
+var iv = setInterval(function () {
  10
+    var y = 0, dy = 1;
  11
+    for (var i = 0; i < 40; i++) {
  12
+        var color = colors[(i + offset) % colors.length];
  13
+        var c = text[(i + offset) % text.length];
  14
+        charm
  15
+            .move(1, dy)
  16
+            .foreground(color)
  17
+            .write(c)
  18
+        ;
  19
+        y += dy;
  20
+        if (y <= 0 || y >= 5) dy *= -1;
  21
+    }
  22
+    charm.position(0, 1);
  23
+    offset ++;
  24
+}, 150);
7  node_modules/charm/example/position.js
... ...
@@ -0,0 +1,7 @@
  1
+var charm = require('charm')(process);
  2
+
  3
+charm.on('^C', process.exit);
  4
+
  5
+charm.position(function (x, y) {
  6
+    console.log('(%d, %d)', x, y);
  7
+});
18  node_modules/charm/example/progress.js
... ...
@@ -0,0 +1,18 @@
  1
+var charm = require('../')();
  2
+charm.pipe(process.stdout);
  3
+
  4
+charm.write('Progress: 0 %');
  5
+var i = 0;
  6
+
  7
+var iv = setInterval(function () {
  8
+    charm.left(i.toString().length + 2);
  9
+    i ++;
  10
+    charm.write(i + ' %');
  11
+    if (i === 100) {
  12
+        charm.end('\nDone!\n');
  13
+        clearInterval(iv);
  14
+    }
  15
+}, 25);
  16
+
  17
+charm.on('^C',process.exit);
  18
+
23  node_modules/charm/example/spin.js
... ...
@@ -0,0 +1,23 @@
  1
+var charm = require('../')(process);
  2
+charm.reset();
  3
+
  4
+var radius = 10;
  5
+var theta = 0;
  6
+var points = [];
  7
+
  8
+var iv = setInterval(function () {
  9
+    var x = 2 + (radius + Math.cos(theta) * radius) * 2;
  10
+    var y = 2 + radius + Math.sin(theta) * radius;
  11
+    
  12
+    points.unshift([ x, y ]);
  13
+    var colors = [ 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta' ];
  14
+    
  15
+    points.forEach(function (p, i) {
  16
+        charm.position(p[0], p[1]);
  17
+        var c = colors[Math.floor(i / 12)];
  18
+        charm.background(c).write(' ')
  19
+    });
  20
+    points = points.slice(0, 12 * colors.length - 1);
  21
+    
  22
+    theta += Math.PI / 40;
  23
+}, 50);
293  node_modules/charm/index.js
... ...
@@ -0,0 +1,293 @@
  1
+var tty = require('tty');
  2
+var encode = require('./lib/encode');
  3
+var Stream = require('stream').Stream;
  4
+
  5
+var exports = module.exports = function () {
  6
+    var input = null;
  7
+    function setInput (s) {
  8
+        if (input) throw new Error('multiple inputs specified')
  9
+        else input = s
  10
+    }
  11
+    
  12
+    var output = null;
  13
+    function setOutput (s) {
  14
+        if (output) throw new Error('multiple outputs specified')
  15
+        else output = s
  16
+    }
  17
+    
  18
+    for (var i = 0; i < arguments.length; i++) {
  19
+        var arg = arguments[i];
  20
+        if (!arg) continue;
  21
+        if (arg.readable) setInput(arg)
  22
+        else if (arg.stdin || arg.input) setInput(arg.stdin || arg.input)
  23
+        
  24
+        if (arg.writable) setOutput(arg)
  25
+        else if (arg.stdout || arg.output) setOutput(arg.stdout || arg.output)
  26
+        
  27
+    }
  28
+    
  29
+    if (input && typeof input.fd === 'number' && tty.isatty(input.fd)) {
  30
+        if (process.stdin.setRawMode) {
  31
+            process.stdin.setRawMode(true);
  32
+        }
  33
+        else tty.setRawMode(true);
  34
+    }
  35
+    
  36
+    var charm = new Charm;
  37
+    if (input) {
  38
+        input.pipe(charm);
  39
+        input.resume();
  40
+    }
  41
+    
  42
+    if (output) {
  43
+        charm.pipe(output);
  44
+    }
  45
+    
  46
+    return charm;
  47
+};
  48
+
  49
+function Charm () {
  50
+    this.writable = true;
  51
+    this.readable = true;
  52
+    this.pending = [];
  53
+}
  54
+
  55
+Charm.prototype = new Stream;
  56
+
  57
+Charm.prototype.write = function (buf) {
  58
+    var self = this;
  59
+    
  60
+    if (self.pending.length) {
  61
+        var codes = extractCodes(buf);
  62
+        var matched = false;
  63
+        
  64
+        for (var i = 0; i < codes.length; i++) {
  65
+            for (var j = 0; j < self.pending.length; j++) {
  66
+                var cb = self.pending[j];
  67
+                if (cb(codes[i])) {
  68
+                    matched = true;
  69
+                    self.pending.splice(j, 1);
  70
+                    break;
  71
+                }
  72
+            }
  73
+        }
  74
+        
  75
+        if (matched) return;
  76
+    }
  77
+    
  78
+    if (buf.length === 1) {
  79
+        if (buf[0] === 3) self.emit('^C');
  80
+        if (buf[0] === 4) self.emit('^D');
  81
+    }
  82
+    
  83
+    self.emit('data', buf);
  84
+    
  85
+    return self;
  86
+};
  87
+
  88
+
  89
+Charm.prototype.destroy = function () {
  90
+    this.end();
  91
+};
  92
+
  93
+Charm.prototype.end = function (buf) {
  94
+    if (buf) this.write(buf);
  95
+    this.emit('end');
  96
+};
  97
+
  98
+Charm.prototype.reset = function (cb) {
  99
+    this.write(encode('c'));
  100
+    return this;
  101
+};
  102
+
  103
+Charm.prototype.position = function (x, y) {
  104
+    // get/set absolute coordinates
  105
+    if (typeof x === 'function') {
  106
+        var cb = x;
  107
+        this.pending.push(function (buf) {
  108
+            if (buf[0] === 27 && buf[1] === encode.ord('[')
  109
+            && buf[buf.length-1] === encode.ord('R')) {
  110
+                var pos = buf.toString()
  111
+                    .slice(2,-1)
  112
+                    .split(';')
  113
+                    .map(Number)
  114
+                ;
  115
+                cb(pos[1], pos[0]);
  116
+                return true;
  117
+            }
  118
+        });
  119
+        this.write(encode('[6n'));
  120
+    }
  121
+    else {
  122
+        this.write(encode(
  123
+            '[' + Math.floor(y) + ';' + Math.floor(x) + 'f'
  124
+        ));
  125
+    }
  126
+    return this;
  127
+};
  128
+
  129
+Charm.prototype.move = function (x, y) {
  130
+    // set relative coordinates
  131
+    var bufs = [];
  132
+    
  133
+    if (y < 0) this.up(-y)
  134
+    else if (y > 0) this.down(y)
  135
+    
  136
+    if (x > 0) this.right(x)
  137
+    else if (x < 0) this.left(-x)
  138
+    
  139
+    return this;
  140
+};
  141
+
  142
+Charm.prototype.up = function (y) {
  143
+    if (y === undefined) y = 1;
  144
+    this.write(encode('[' + Math.floor(y) + 'A'));
  145
+    return this;
  146
+};
  147
+
  148
+Charm.prototype.down = function (y) {
  149
+    if (y === undefined) y = 1;
  150
+    this.write(encode('[' + Math.floor(y) + 'B'));
  151
+    return this;
  152
+};
  153
+
  154
+Charm.prototype.right = function (x) {
  155
+    if (x === undefined) x = 1;
  156
+    this.write(encode('[' + Math.floor(x) + 'C'));
  157
+    return this;
  158
+};
  159
+
  160
+Charm.prototype.left = function (x) {
  161
+    if (x === undefined) x = 1;
  162
+    this.write(encode('[' + Math.floor(x) + 'D'));
  163
+    return this;
  164
+};
  165
+
  166
+Charm.prototype.column = function (x) {
  167
+    this.write(encode('[' + Math.floor(x) + 'G'));
  168
+    return this;
  169
+};
  170
+
  171
+Charm.prototype.push = function (withAttributes) {
  172
+    this.write(encode(withAttributes ? '7' : '[s'));
  173
+    return this;
  174
+};
  175
+
  176
+Charm.prototype.pop = function (withAttributes) {
  177
+    this.write(encode(withAttributes ? '8' : '[u'));
  178
+    return this;
  179
+};
  180
+
  181
+Charm.prototype.erase = function (s) {
  182
+    if (s === 'end' || s === '$') {
  183
+        this.write(encode('[K'));
  184
+    }
  185
+    else if (s === 'start' || s === '^') {
  186
+        this.write(encode('[1K'));
  187
+    }
  188
+    else if (s === 'line') {
  189
+        this.write(encode('[2K'));
  190
+    }
  191
+    else if (s === 'down') {
  192
+        this.write(encode('[J'));
  193
+    }
  194
+    else if (s === 'up') {
  195
+        this.write(encode('[1J'));
  196
+    }
  197
+    else if (s === 'screen') {
  198
+        this.write(encode('[1J'));
  199
+    }
  200
+    else {
  201
+        this.emit('error', new Error('Unknown erase type: ' + s));
  202
+    }
  203
+    return this;
  204
+};
  205
+
  206
+Charm.prototype.display = function (attr) {
  207
+    var c = {
  208
+        reset : 0,
  209
+        bright : 1,
  210
+        dim : 2,
  211
+        underscore : 4,
  212
+        blink : 5,
  213
+        reverse : 7,
  214
+        hidden : 8
  215
+    }[attr];
  216
+    if (c === undefined) {
  217
+        this.emit('error', new Error('Unknown attribute: ' + attr));
  218
+    }
  219
+    this.write(encode('[' + c + 'm'));
  220
+    return this;
  221
+};
  222
+
  223
+Charm.prototype.foreground = function (color) {
  224
+    if (typeof color === 'number') {
  225
+        if (color < 0 || color >= 256) {
  226
+            this.emit('error', new Error('Color out of range: ' + color));
  227
+        }
  228
+        this.write(encode('[38;5;' + color + 'm'));
  229
+    }
  230
+    else {
  231
+        var c = {
  232
+            black : 30,
  233
+            red : 31,
  234
+            green : 32,
  235
+            yellow : 33,
  236
+            blue : 34,
  237
+            magenta : 35,
  238
+            cyan : 36,
  239
+            white : 37
  240
+        }[color.toLowerCase()];
  241
+        
  242
+        if (!c) this.emit('error', new Error('Unknown color: ' + color));
  243
+        this.write(encode('[' + c + 'm'));
  244
+    }
  245
+    return this;
  246
+};
  247
+
  248
+Charm.prototype.background = function (color) {
  249
+    if (typeof color === 'number') {
  250
+        if (color < 0 || color >= 256) {
  251
+            this.emit('error', new Error('Color out of range: ' + color));
  252
+        }
  253
+        this.write(encode('[48;5;' + color + 'm'));
  254
+    }
  255
+    else {
  256
+        var c = {
  257
+          black : 40,
  258
+          red : 41,
  259
+          green : 42,
  260
+          yellow : 43,
  261
+          blue : 44,
  262
+          magenta : 45,
  263
+          cyan : 46,
  264
+          white : 47
  265
+        }[color.toLowerCase()];
  266
+        
  267
+        if (!c) this.emit('error', new Error('Unknown color: ' + color));
  268
+        this.write(encode('[' + c + 'm'));
  269
+    }
  270
+    return this;
  271
+};
  272
+
  273
+Charm.prototype.cursor = function (visible) {
  274
+    this.write(encode(visible ? '[?25h' : '[?25l'));
  275
+    return this;
  276
+};
  277
+
  278
+var extractCodes = exports.extractCodes = function (buf) {
  279
+    var codes = [];
  280
+    var start = -1;
  281
+    
  282
+    for (var i = 0; i < buf.length; i++) {
  283
+        if (buf[i] === 27) {
  284
+            if (start >= 0) codes.push(buf.slice(start, i));
  285
+            start = i;
  286
+        }
  287
+        else if (start >= 0 && i === buf.length - 1) {
  288
+            codes.push(buf.slice(start));
  289
+        }
  290
+    }
  291
+    
  292
+    return codes;
  293
+}
18  node_modules/charm/lib/encode.js
... ...
@@ -0,0 +1,18 @@
  1
+var encode = module.exports = function (xs) {
  2
+    function bytes (s) {
  3
+        if (typeof s === 'string') {
  4
+            return s.split('').map(ord);
  5
+        }
  6
+        else if (Array.isArray(s)) {
  7
+            return s.reduce(function (acc, c) {
  8
+                return acc.concat(bytes(c));
  9
+            }, []);
  10
+        }
  11
+    }
  12
+    
  13
+    return new Buffer([ 0x1b ].concat(bytes(xs)));
  14
+};
  15
+
  16
+var ord = encode.ord = function ord (c) {
  17
+    return c.charCodeAt(0)
  18
+};
40  node_modules/charm/package.json
... ...
@@ -0,0 +1,40 @@
  1
+{
  2
+  "name": "charm",
  3
+  "version": "0.1.0",
  4
+  "description": "ansi control sequences for terminal cursor hopping and colors",
  5
+  "main": "index.js",
  6
+  "directories": {
  7
+    "lib": ".",
  8
+    "example": "example",
  9
+    "test": "test"
  10
+  },
  11
+  "repository": {
  12
+    "type": "git",
  13
+    "url": "http://github.com/substack/node-charm.git"
  14
+  },
  15
+  "keywords": [
  16
+    "terminal",
  17
+    "ansi",
  18
+    "cursor",
  19
+    "color",
  20
+    "console",
  21
+    "control",
  22
+    "escape",
  23
+    "sequence"
  24
+  ],
  25
+  "author": {
  26
+    "name": "James Halliday",
  27
+    "email": "mail@substack.net",
  28
+    "url": "http://substack.net"
  29
+  },
  30
+  "license": "MIT/X11",
  31
+  "engine": {
  32
+    "node": ">=0.4"
  33
+  },
  34
+  "readme": "charm\n=====\n\nUse\n[ansi terminal characters](http://www.termsys.demon.co.uk/vtansi.htm)\nto write colors and cursor positions.\n\n![me lucky charms](http://substack.net/images/charms.png)\n\nexample\n=======\n\nlucky\n-----\n\n````javascript\nvar charm = require('charm')();\ncharm.pipe(process.stdout);\ncharm.reset();\n\nvar colors = [ 'red', 'cyan', 'yellow', 'green', 'blue' ];\nvar text = 'Always after me lucky charms.';\n\nvar offset = 0;\nvar iv = setInterval(function () {\n    var y = 0, dy = 1;\n    for (var i = 0; i < 40; i++) {\n        var color = colors[(i + offset) % colors.length];\n        var c = text[(i + offset) % text.length];\n        charm\n            .move(1, dy)\n            .foreground(color)\n            .write(c)\n        ;\n        y += dy;\n        if (y <= 0 || y >= 5) dy *= -1;\n    }\n    charm.position(0, 1);\n    offset ++;\n}, 150);\n````\n\nevents\n======\n\nCharm objects pass along the data events from their input stream except for\nevents generated from querying the terminal device.\n\nBecause charm puts stdin into raw mode, charm emits two special events: \"^C\" and\n\"^D\" when the user types those combos. It's super convenient with these events\nto do:\n\n````javascript\ncharm.on('^C', process.exit)\n````\n\nmethods\n=======\n\nvar charm = require('charm')(param or stream, ...)\n--------------------------------------------------\n\nCreate a new readable/writable `charm` stream.\n\nYou can pass in readable or writable streams as parameters and they will be\npiped to or from accordingly. You can also pass `process` in which case\n`process.stdin` and `process.stdout` will be used.\n\nYou can `pipe()` to and from the `charm` object you get back.\n\ncharm.reset()\n-------------\n\nReset the entire screen, like the /usr/bin/reset command.\n\ncharm.destroy(), charm.end()\n----------------------------\n\nEmit an `\"end\"` event downstream.\n\ncharm.write(msg)\n----------------\n\nPass along `msg` to the output stream.\n\ncharm.position(x, y)\n--------------------\n\nSet the cursor position to the absolute coordinates `x, y`.\n\ncharm.position(cb)\n------------------\n\nQuery the absolute cursor position from the input stream through the output\nstream (the shell does this automatically) and get the response back as\n`cb(x, y)`.\n\ncharm.move(x, y)\n----------------\n\nMove the cursor position by the relative coordinates `x, y`.\n\ncharm.up(y)\n-----------\n\nMove the cursor up by `y` rows.\n\ncharm.down(y)\n-------------\n\nMove the cursor down by `y` rows.\n\ncharm.left(x)\n-------------\n\nMove the cursor left by `x` columns.\n\ncharm.right(x)\n--------------\n\nMove the cursor right by `x` columns.\n\ncharm.push(withAttributes=false)\n--------------------------------\n\nPush the cursor state and optionally the attribute state.\n\ncharm.pop(withAttributes=false)\n-------------------------------\n\nPop the cursor state and optionally the attribute state.\n\ncharm.erase(s)\n--------------\n\nErase a region defined by the string `s`.\n\n`s` can be:\n\n* end - erase from the cursor to the end of the line\n* start - erase from the cursor to the start of the line\n* line - erase the current line\n* down - erase everything below the current line\n* up - erase everything above the current line\n* screen - erase the entire screen\n\ncharm.display(attr)\n-------------------\n\nSet the display mode with the string `attr`.\n\n`attr` can be:\n\n* reset\n* bright\n* dim\n* underscore\n* blink\n* reverse\n* hidden\n\ncharm.foreground(color)\n-----------------------\n\nSet the foreground color with the string `color`, which can be:\n\n* red\n* yellow\n* green\n* blue\n* cyan\n* magenta\n* black\n* white\n\nor `color` can be an integer from 0 to 255, inclusive.\n\ncharm.background(color)\n-----------------------\n\nSet the background color with the string `color`, which can be:\n\n* red\n* yellow\n* green\n* blue\n* cyan\n* magenta\n* black\n* white\n\nor `color` can be an integer from 0 to 255, inclusive.\n\ncharm.cursor(visible)\n---------------------\n\nSet the cursor visibility with a boolean `visible`.\n\ninstall\n=======\n\nWith [npm](http://npmjs.org) do:\n\n```\nnpm install charm\n```\n",
  35
+  "_id": "charm@0.1.0",
  36
+  "dist": {
  37
+    "shasum": "9efebfebbb7c9cd2188c5ecabd7f385f691ff679"
  38
+  },
  39
+  "_from": "charm@0.1.0"
  40
+}
10  package.json
... ...
@@ -0,0 +1,10 @@
  1
+{
  2
+  "name": "life.js",
  3
+  "version": "0.1.0",
  4
+  "description": "an implementation of conway's game of life",
  5
+  "main": "life.js",
  6
+  "dependencies": {
  7
+    "charm": "0.1.0"
  8
+  },
  9
+  "author": "frangio"
  10
+}

0 notes on commit 6b482b7

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