Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-10-24 10:30:02 +0400
committerisaacs <i@izs.me>2013-10-24 10:30:02 +0400
commit3fca336b686c3cf78dbf0fc816eaa4648db16f81 (patch)
treed97a07a21d6399f7659f8b41590eed1f734c7cb6 /node_modules/ansi
parent96d08ed3c0afc5eab50045061d47cebee5cb9edd (diff)
ansi@0.2.1
Diffstat (limited to 'node_modules/ansi')
-rw-r--r--node_modules/ansi/README.md8
-rw-r--r--node_modules/ansi/color-spaces.pl67
-rwxr-xr-xnode_modules/ansi/examples/cursorPosition.js12
-rwxr-xr-xnode_modules/ansi/examples/imgcat/index.js50
-rw-r--r--node_modules/ansi/examples/imgcat/yoshi.pngbin1341 -> 0 bytes
-rwxr-xr-xnode_modules/ansi/examples/starwars.js9
-rw-r--r--node_modules/ansi/lib/ansi.js45
-rw-r--r--node_modules/ansi/package.json28
8 files changed, 137 insertions, 82 deletions
diff --git a/node_modules/ansi/README.md b/node_modules/ansi/README.md
index 7b427fe4c..2f9bb140a 100644
--- a/node_modules/ansi/README.md
+++ b/node_modules/ansi/README.md
@@ -2,8 +2,6 @@ ansi.js
=========
### Advanced ANSI formatting tool for Node.js
-![](http://f.cl.ly/items/0D3w3d1W443f2z3X361G/Screen%20Shot%202012-01-26%20at%202.18.31%20AM.png)
-
`ansi.js` is a module for Node.js that provides an easy-to-use API for
writing ANSI escape codes to `Stream` instances. ANSI escape codes are used to do
fancy things in a terminal window, like render text in colors, delete characters,
@@ -91,9 +89,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-----------
-
-Additionally:
-
- * The `yoshi.png` file inside `examples/imgcat` is copyright to Nintendo, Inc.
diff --git a/node_modules/ansi/color-spaces.pl b/node_modules/ansi/color-spaces.pl
new file mode 100644
index 000000000..8774c0446
--- /dev/null
+++ b/node_modules/ansi/color-spaces.pl
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+# Author: Todd Larason <jtl@molehill.org>
+# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $
+
+print "256 color mode\n\n";
+
+# display back ground colors
+
+for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) {
+
+# first the system ones:
+print "System colors:\n";
+for ($color = 0; $color < 8; $color++) {
+ print "\x1b[${fgbg};5;${color}m::";
+}
+print "\x1b[0m\n";
+for ($color = 8; $color < 16; $color++) {
+ print "\x1b[${fgbg};5;${color}m::";
+}
+print "\x1b[0m\n\n";
+
+# now the color cube
+print "Color cube, 6x6x6:\n";
+for ($green = 0; $green < 6; $green++) {
+ for ($red = 0; $red < 6; $red++) {
+ for ($blue = 0; $blue < 6; $blue++) {
+ $color = 16 + ($red * 36) + ($green * 6) + $blue;
+ print "\x1b[${fgbg};5;${color}m::";
+ }
+ print "\x1b[0m ";
+ }
+ print "\n";
+}
+
+# now the grayscale ramp
+print "Grayscale ramp:\n";
+for ($color = 232; $color < 256; $color++) {
+ print "\x1b[${fgbg};5;${color}m::";
+}
+print "\x1b[0m\n\n";
+
+}
+
+print "Examples for the 3-byte color mode\n\n";
+
+for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) {
+
+# now the color cube
+print "Color cube\n";
+for ($green = 0; $green < 256; $green+=51) {
+ for ($red = 0; $red < 256; $red+=51) {
+ for ($blue = 0; $blue < 256; $blue+=51) {
+ print "\x1b[${fgbg};2;${red};${green};${blue}m::";
+ }
+ print "\x1b[0m ";
+ }
+ print "\n";
+}
+
+# now the grayscale ramp
+print "Grayscale ramp:\n";
+for ($gray = 8; $gray < 256; $gray+=10) {
+ print "\x1b[${fgbg};2;${gray};${gray};${gray}m::";
+}
+print "\x1b[0m\n\n";
+
+}
diff --git a/node_modules/ansi/examples/cursorPosition.js b/node_modules/ansi/examples/cursorPosition.js
index 0f45bdbe5..50f964490 100755
--- a/node_modules/ansi/examples/cursorPosition.js
+++ b/node_modules/ansi/examples/cursorPosition.js
@@ -5,7 +5,7 @@ var cursor = require('../')(process.stdout)
// listen for the queryPosition report on stdin
process.stdin.resume()
-tty.setRawMode(true)
+raw(true)
process.stdin.once('data', function (b) {
var match = /\[(\d+)\;(\d+)R$/.exec(b.toString())
@@ -15,10 +15,18 @@ process.stdin.once('data', function (b) {
}
// cleanup and close stdin
- tty.setRawMode(false)
+ raw(false)
process.stdin.pause()
})
// send the query position request code to stdout
cursor.queryPosition()
+
+function raw (mode) {
+ if (process.stdin.setRawMode) {
+ process.stdin.setRawMode(mode)
+ } else {
+ tty.setRawMode(mode)
+ }
+}
diff --git a/node_modules/ansi/examples/imgcat/index.js b/node_modules/ansi/examples/imgcat/index.js
deleted file mode 100755
index 5ff2c1394..000000000
--- a/node_modules/ansi/examples/imgcat/index.js
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env node
-
-process.title = 'imgcat'
-
-var ansi = require('../../')
- , cursor = ansi(process.stdout, { enabled: true })
- , tty = require('tty')
- , Canvas = require('canvas')
- , imageFile = process.argv[2] || __dirname + '/yoshi.png'
- , screenWidth = process.stdout.isTTY ? process.stdout.getWindowSize()[0] : Infinity
- , maxWidth = parseInt(process.argv[3], 10) || screenWidth
- , image = require('fs').readFileSync(imageFile)
- , pixel = ' '
- , alphaThreshold = 0
-
-var img = new Canvas.Image();
-img.src = image;
-
-function draw () {
- var width = maxWidth / pixel.length
- , scaleW = img.width > width ? width / img.width : 1
- , w = Math.floor(img.width * scaleW)
- , h = Math.floor(img.height * scaleW);
-
- var canvas = new Canvas(w, h)
- , ctx = canvas.getContext('2d');
-
- ctx.drawImage(img, 0, 0, w, h);
-
- var data = ctx.getImageData(0, 0, w, h).data;
-
- for (var i=0, l=data.length; i<l; i+=4) {
- var r = data[i]
- , g = data[i+1]
- , b = data[i+2]
- , alpha = data[i+3];
- if (alpha > alphaThreshold) {
- cursor.bg.rgb(r, g, b);
- } else {
- cursor.bg.reset();
- }
- process.stdout.write(pixel);
- if ((i/4|0) % w === (w-1)) {
- cursor.bg.reset();
- process.stdout.write('\n');
- }
- }
-}
-
-draw();
diff --git a/node_modules/ansi/examples/imgcat/yoshi.png b/node_modules/ansi/examples/imgcat/yoshi.png
deleted file mode 100644
index 267ede254..000000000
--- a/node_modules/ansi/examples/imgcat/yoshi.png
+++ /dev/null
Binary files differ
diff --git a/node_modules/ansi/examples/starwars.js b/node_modules/ansi/examples/starwars.js
index a1fcad42a..06f8ba847 100755
--- a/node_modules/ansi/examples/starwars.js
+++ b/node_modules/ansi/examples/starwars.js
@@ -9,6 +9,7 @@ process.title = 'starwars'
var net = require('net')
, cursor = require('../')(process.stdout)
+ , color = process.argv[2]
// enable "raw mode" so that keystrokes aren't visible
process.stdin.resume()
@@ -22,6 +23,9 @@ if (process.stdin.setRawMode) {
var socket = net.connect(23, 'towel.blinkenlights.nl')
socket.on('connect', function () {
+ if (color in cursor.fg) {
+ cursor.fg[color]()
+ }
cursor.hide()
socket.pipe(process.stdout)
})
@@ -35,5 +39,8 @@ process.stdin.on('data', function (data) {
})
process.on('exit', function () {
- cursor.show().write('\n')
+ cursor
+ .show()
+ .fg.reset()
+ .write('\n')
})
diff --git a/node_modules/ansi/lib/ansi.js b/node_modules/ansi/lib/ansi.js
index cc883e8d8..52fc8ec8b 100644
--- a/node_modules/ansi/lib/ansi.js
+++ b/node_modules/ansi/lib/ansi.js
@@ -12,7 +12,7 @@
*/
var emitNewlineEvents = require('./newlines')
- , prefix = '\033[' // For all escape codes
+ , prefix = '\x1b[' // For all escape codes
, suffix = 'm' // Only for color codes
/**
@@ -120,6 +120,11 @@ function Cursor (stream, options) {
}
this.enabled = !!this.enabled
+ // then `buffering` is true, then `write()` calls are buffered in
+ // memory until `flush()` is invoked
+ this.buffering = !!(options && options.buffering)
+ this._buffer = []
+
// controls the foreground and background colors
this.fg = this.foreground = new Colorer(this, 0)
this.bg = this.background = new Colorer(this, 10)
@@ -145,8 +150,40 @@ exports.Cursor = Cursor
* the chaining going.
*/
-Cursor.prototype.write = function () {
- this.stream.write.apply(this.stream, arguments)
+Cursor.prototype.write = function (data) {
+ if (this.buffering) {
+ this._buffer.push(arguments)
+ } else {
+ this.stream.write.apply(this.stream, arguments)
+ }
+ return this
+}
+
+/**
+ * Buffer `write()` calls into memory.
+ *
+ * @api public
+ */
+
+Cursor.prototype.buffer = function () {
+ this.buffering = true
+ return this
+}
+
+/**
+ * Write out the in-memory buffer.
+ *
+ * @api public
+ */
+
+Cursor.prototype.flush = function () {
+ this.buffering = false
+ var str = this._buffer.map(function (args) {
+ if (args.length != 1) throw new Error('unexpected args length! ' + args.length);
+ return args[0];
+ }).join('');
+ this._buffer.splice(0); // empty
+ this.write(str);
return this
}
@@ -237,7 +274,7 @@ Object.keys(colors).forEach(function (color) {
*/
Cursor.prototype.beep = function () {
- this.enabled && this.write('\007')
+ this.enabled && this.write('\x07')
return this
}
diff --git a/node_modules/ansi/package.json b/node_modules/ansi/package.json
index d449d827e..e7cde2604 100644
--- a/node_modules/ansi/package.json
+++ b/node_modules/ansi/package.json
@@ -11,7 +11,7 @@
"256",
"stream"
],
- "version": "0.1.2",
+ "version": "0.2.1",
"author": {
"name": "Nathan Rajlich",
"email": "nathan@tootallnate.net",
@@ -25,32 +25,26 @@
"bin": {
"beep": "./examples/beep/index.js",
"clear": "./examples/clear/index.js",
- "imgcat": "./examples/imgcat/index.js",
"starwars": "./examples/starwars.js"
},
"scripts": {
"test": "mocha --reporter spec"
},
"devDependencies": {
- "mocha": "*",
- "canvas": "*"
+ "mocha": "*"
},
"engines": {
"node": "*"
},
- "_npmUser": {
- "name": "isaacs",
- "email": "i@izs.me"
- },
- "_id": "ansi@0.1.2",
- "dependencies": {},
- "optionalDependencies": {},
- "_engineSupported": true,
- "_npmVersion": "1.1.24",
- "_nodeVersion": "v0.7.10-pre",
- "_defaultsLoaded": true,
+ "readme": "ansi.js\n=========\n### Advanced ANSI formatting tool for Node.js\n\n`ansi.js` is a module for Node.js that provides an easy-to-use API for\nwriting ANSI escape codes to `Stream` instances. ANSI escape codes are used to do\nfancy things in a terminal window, like render text in colors, delete characters,\nlines, the entire window, or hide and show the cursor, and lots more!\n\nThe code for the example in the screenshot above can be found in the\n`examples/imgcat` directory.\n\n#### Features:\n\n * 256 color support for the terminal!\n * Make a beep sound from your terminal!\n * Works with *any* writable `Stream` instance.\n * Allows you to move the cursor anywhere on the terminal window.\n * Allows you to delete existing contents from the terminal window.\n * Allows you to hide and show the cursor.\n * Converts CSS color codes and RGB values into ANSI escape codes.\n * Low-level; you are in control of when escape codes are used, it's not abstracted.\n\n\nInstallation\n------------\n\nInstall with `npm`:\n\n``` bash\n$ npm install ansi\n```\n\n\nExample\n-------\n\n``` js\nvar ansi = require('ansi')\n , cursor = ansi(process.stdout)\n\n// You can chain your calls forever:\ncursor\n .red() // Set font color to red\n .bg.grey() // Set background color to grey\n .write('Hello World!') // Write 'Hello World!' to stdout\n .bg.reset() // Reset the bgcolor before writing the trailing \\n,\n // to avoid Terminal glitches\n .write('\\n') // And a final \\n to wrap things up\n\n// Rendering modes are persistent:\ncursor.hex('#660000').bold().underline()\n\n// You can use the regular logging functions, text will be green\nconsole.log('This is blood red, bold text')\n\n// To reset just the foreground color:\ncursor.fg.reset()\n\nconsole.log('This will still be bold')\n\n// Clean up after yourself!\ncursor.reset()\n```\n\n\nLicense\n-------\n\n(The MIT License)\n\nCopyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
+ "readmeFilename": "README.md",
+ "bugs": {
+ "url": "https://github.com/TooTallNate/ansi.js/issues"
+ },
+ "_id": "ansi@0.2.1",
"dist": {
- "shasum": "6139b23459bcd74b04572cf56b36102983d0a7d4"
+ "shasum": "76961682ac06d5ea0729af53295ea8f953a0cb21"
},
- "_from": "ansi@~0.1.2"
+ "_from": "ansi@latest",
+ "_resolved": "https://registry.npmjs.org/ansi/-/ansi-0.2.1.tgz"
}