Comparing version 0.0.1 to 0.0.2
@@ -116,2 +116,11 @@ | ||
/** | ||
* Helper function that calls `write()` on the underlying Stream. | ||
*/ | ||
Cursor.prototype.write = function () { | ||
this.stream.write.apply(this.stream, arguments); | ||
return this; | ||
} | ||
/** | ||
* Set up the positional ANSI codes. | ||
@@ -124,2 +133,3 @@ */ | ||
Cursor.prototype[name] = function () { | ||
debug('Cursor#'+name+'()`', arguments); | ||
var c = code; | ||
@@ -129,3 +139,5 @@ if (arguments.length > 0) { | ||
} | ||
this.stream.write(prefix + c); | ||
debug('code:', c); | ||
this.write(prefix + c); | ||
return this; | ||
} | ||
@@ -143,3 +155,4 @@ }); | ||
Cursor.prototype[style] = function () { | ||
this.stream.write(prefix + styles[style] + suffix); | ||
this.write(prefix + styles[style] + suffix); | ||
return this; | ||
} | ||
@@ -149,3 +162,4 @@ | ||
Cursor.prototype['reset'+name] = function () { | ||
this.stream.write(prefix + reset[style] + suffix); | ||
this.write(prefix + reset[style] + suffix); | ||
return this; | ||
} | ||
@@ -161,3 +175,4 @@ }); | ||
Foreground.prototype[color] = function () { | ||
this.cursor.stream.write(prefix + colors[color] + suffix); | ||
this.cursor.write(prefix + colors[color] + suffix); | ||
return this.cursor; | ||
} | ||
@@ -168,37 +183,75 @@ | ||
Background.prototype[color] = function () { | ||
this.cursor.stream.write(prefix + bgCode + suffix); | ||
this.cursor.write(prefix + bgCode + suffix); | ||
return this.cursor; | ||
} | ||
debug('defining `Cursor#`'+color+'`'); | ||
debug('defining `Cursor#'+color+'`'); | ||
Cursor.prototype[color] = function () { | ||
this.foreground[color](); | ||
return this.foreground[color](); | ||
} | ||
}); | ||
/** | ||
* Makes a beep sound! | ||
*/ | ||
Cursor.prototype.beep = function () { | ||
debug('Cursor#beep()'); | ||
this.write('\007'); | ||
return this; | ||
} | ||
/** | ||
* Reset the foreground color. | ||
*/ | ||
Foreground.prototype.reset = function () { | ||
this.cursor.stream.write(prefix + reset.foreground + suffix); | ||
this.cursor.write(prefix + reset.foreground + suffix); | ||
return this.cursor; | ||
} | ||
/** | ||
* Reset the background color. | ||
*/ | ||
Background.prototype.reset = function () { | ||
this.cursor.stream.write(prefix + reset.background + suffix); | ||
this.cursor.write(prefix + reset.background + suffix); | ||
return this.cursor; | ||
} | ||
/** | ||
* resets all ANSI formatting on the stream. | ||
* Resets all ANSI formatting on the stream. | ||
*/ | ||
Cursor.prototype.reset = function () { | ||
this.stream.write(prefix + '0' + suffix); | ||
this.write(prefix + '0' + suffix); | ||
return this; | ||
} | ||
/** | ||
* Sets the foreground color with the given RGB values. | ||
* The closest match out of the 216 colors is picked. | ||
*/ | ||
Foreground.prototype.rgb = function (r, g, b) { | ||
this.cursor.stream.write(prefix + '38;5;' + rgb(r, g, b) + suffix); | ||
this.cursor.write(prefix + '38;5;' + rgb(r, g, b) + suffix); | ||
return this.cursor; | ||
} | ||
/** | ||
* Sets the background color with the given RGB values. | ||
* The closest match out of the 216 colors is picked. | ||
*/ | ||
Background.prototype.rgb = function (r, g, b) { | ||
this.cursor.stream.write(prefix + '48;5;' + rgb(r, g, b) + suffix); | ||
this.cursor.write(prefix + '48;5;' + rgb(r, g, b) + suffix); | ||
return this.cursor; | ||
} | ||
/** | ||
* Same as `cursor.fg.rgb()`. | ||
*/ | ||
Cursor.prototype.rgb = function (r, g, b) { | ||
this.foreground.rgb(r, g, b); | ||
return this.foreground.rgb(r, g, b); | ||
} | ||
@@ -208,2 +261,3 @@ | ||
* Accepts CSS color codes for use with ANSI escape codes. | ||
* For example: `#FF000` would be bright red. | ||
*/ | ||
@@ -213,7 +267,11 @@ | ||
var rgb = hex(color); | ||
this.rgb(rgb[0], rgb[1], rgb[2]); | ||
return this.rgb(rgb[0], rgb[1], rgb[2]); | ||
} | ||
/** | ||
* Same as `cursor.fg.hex()`. | ||
*/ | ||
Cursor.prototype.hex = function (color) { | ||
this.foreground.hex(color); | ||
return this.foreground.hex(color); | ||
} | ||
@@ -220,0 +278,0 @@ |
{ "name": "ansi" | ||
, "description": "ANSI formatting tool for Node.js" | ||
, "description": "Advanced ANSI formatting tool for Node.js" | ||
, "keywords": [ "ansi", "formatting", "cursor", "color", "terminal", "rgb", "256", "stream" ] | ||
, "version": "0.0.1" | ||
, "version": "0.0.2" | ||
, "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)" | ||
@@ -18,3 +18,3 @@ , "repository": { "type": "git", "url": "git://github.com/TooTallNate/ansi.js.git" } | ||
} | ||
, "engines": { "node": ">= 0.4.0 && < 0.7.0" } | ||
, "engines": { "node": ">= 0.4.0 && < 0.9.0" } | ||
} |
ansi.js | ||
========= | ||
### ANSI formatting tool for Node.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 writes provides an easy-to-use API for | ||
`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 | ||
@@ -58,1 +58,28 @@ fancy things in a terminal window, like render text in colors, delete characters, | ||
``` | ||
License | ||
------- | ||
(The MIT License) | ||
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net> | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
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. |
17
test.js
var ansi = require('./') | ||
, cursor = ansi(process.stdout); | ||
, cursor = ansi(process.stdout) | ||
//cursor.eraseData(2); | ||
cursor.rgb(66,68,59) | ||
console.log('test'); | ||
cursor.blue() | ||
.bg.yellow() | ||
.bold() | ||
.write('test') | ||
.reset() | ||
.back(3).write('nate') | ||
.write('\n'); | ||
cursor.down(5); | ||
process.stdout.write('bitches!!!') | ||
cursor.forward(10); | ||
console.log('baller!!!') |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
43694
9
327
85
2
1