From 296e23da4020be903fc281cfcf4b1294daecfd2d Mon Sep 17 00:00:00 2001 From: christos constandinou Date: Wed, 29 Feb 2012 22:10:25 +0000 Subject: [PATCH] first commit --- .gitignore | 4 ++++ .npmignore | 5 +++++ LICENSE | 9 +++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ ansi-pansi.js | 14 ++++++++++++++ package.json | 20 ++++++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 ansi-pansi.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67d6c3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store + +.idea/ +npm-debug.log diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..4d86ed3 --- /dev/null +++ b/.npmignore @@ -0,0 +1,5 @@ +.DS_Store +.git* +.idea/ + +npm-debug.log diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3d98f9f --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +(The MIT License) + +Copyright (c) 2011 christos "constantology" constandinou http://muigui.com + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..362307a --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# ansi pansi + +Basic ansi formatting, foreground and background colours for use with CLIs. + +## installation + +``` + + npm install ansi-pansi + +``` + +## usage + +```javascript + + var ansiformat = require( 'ansi-pansi' ); + + console.log( ansiformat( 'foo', 'bold blue bg_yellow' ) ); + // prints => 'foo' to the console in blue, bold on a yellow background. + +``` + +## formatting and colour options +You can use the below codes concatenated with either a plus `+` or a space ` ` character as shown in the example above. + +### formatting +`bold`, `italic`, `underline`, `blink`, `reverse`, `hidden`. + +### foreground colours +`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white` + +### background colours +`bg_black`, `bg_red`, `bg_green`, `bg_yellow`, `bg_blue`, `bg_magenta`, `bg_cyan`, `bg_white` + +## License + +(The MIT License) + +Copyright © 2012 christos "constantology" constandinou http://muigui.com + +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. diff --git a/ansi-pansi.js b/ansi-pansi.js new file mode 100644 index 0000000..3bcc1c4 --- /dev/null +++ b/ansi-pansi.js @@ -0,0 +1,14 @@ +var code = { + reset : 0, +// formatting + bold : 1, italic : 3, underline : 4, blink : 5, reverse : 7, hidden : 8, +// foreground colours + black : 30, red : 31, green : 32, yellow : 33, blue : 34, magenta : 35, cyan : 36, white : 37, +// background colours + bg_black : 40, bg_red : 41, bg_green : 42, bg_yellow : 43, bg_blue : 44, bg_magenta : 45, bg_cyan : 46, bg_white : 47 +}; + +exports = function ansi_pansi( str, colour ) { + var f = colour.split( /[\s\+]/ ).reduce( function( s, a ) { return ( a in code ) ? s += code[a] + ';' : s; }, '' ); + return ( f.length ? '\033[' + f + 'm' : f ) + str + '\033[0m'; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..19f473b --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "author" : { + "name" : "constantology", + "email" : "constantology@gmail.com", + "url" : "http://muigui.com" + }, + "description" : "Basic ansi formatting, foreground and background colours for use with CLIs.", + "keywords" : ["ansi", "color", "colour", "cli", "console"], + "licenses" : [ { + "type" : "MIT", + "url" : "https://raw.github.com/constantology/ansi-pansi/master/LICENSE" + } ], + "main" : "./ansi-pansi.js", + "name" : "ansi-pansi", + "repository" : { + "type" : "git", + "url" : "git@github.com:constantology/ansi-pansi.git" + }, + "version" : "0.0.1" +}