diff --git a/ReadMe.md b/ReadMe.md
index a1f4dd0..3582d35 100644
--- a/ReadMe.md
+++ b/ReadMe.md
@@ -8,6 +8,7 @@
sys.puts('hello'.green); // outputs green text
sys.puts('i like cake and pies'.underline.red) // outputs red underlined text
sys.puts('inverse the color'.inverse); // inverses the color
+ sys.puts('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)
colors and styles!
- bold
@@ -26,4 +27,4 @@
### Authors
-#### Alexis Sellier (cloudhead) , Marak Squires
\ No newline at end of file
+#### Alexis Sellier (cloudhead) , Marak Squires , Justin Campbell
\ No newline at end of file
diff --git a/colors.js b/colors.js
index 74bedc8..d0a3e2b 100644
--- a/colors.js
+++ b/colors.js
@@ -23,6 +23,7 @@ THE SOFTWARE.
*/
+var sys = require('sys');
['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'].forEach(function (style) {
Object.defineProperty(String.prototype, style, {
@@ -32,21 +33,41 @@ THE SOFTWARE.
});
});
+Object.defineProperty(String.prototype, 'rainbow', {
+ get: function () {
+ var rainbowcolors = ['red','yellow','green','blue','magenta']; //RoY G BiV
+ var exploded = this.split("");
+ var i=0;
+ exploded = exploded.map(function(letter) {
+ if (letter==" ") {
+ return letter;
+ } else {
+ return stylize(letter,rainbowcolors[i++ % rainbowcolors.length]);
+ }
+ });
+ return exploded.join("");
+ }
+});
+
function stylize(str, style) {
var styles = {
- 'bold' : [1, 22],
+ //styles
+ 'bold' : [1, 22],
'italic' : [3, 23],
'underline' : [4, 24],
- 'yellow' : [33, 39],
- 'cyan' : [36, 39],
+ 'inverse' : [7, 27],
+ //grayscale
'white' : [37, 39],
- 'green' : [32, 39],
- 'red' : [31, 39],
'grey' : [90, 39],
- 'blue' : [34, 39],
+ 'black' : [90, 39],
+ //colors
+ 'blue' : [34, 39],
+ 'cyan' : [36, 39],
+ 'green' : [32, 39],
'magenta' : [35, 39],
- 'inverse' : [7, 27]
+ 'red' : [31, 39],
+ 'yellow' : [33, 39]
};
return '\033[' + styles[style][0] + 'm' + str +
'\033[' + styles[style][1] + 'm';
-};
+};
\ No newline at end of file
diff --git a/example.js b/example.js
index d31c7c8..a990998 100644
--- a/example.js
+++ b/example.js
@@ -1,6 +1,6 @@
var sys = require('sys');
var colors = require('./colors');
-sys.puts('C'.yellow+'o'.red+'l'.grey+'o'.cyan+'r'.magenta+'s'.magenta+' are '.green + 'fun!'.yellow);
+sys.puts('Colors are fun!'.rainbow);
sys.puts('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
-sys.puts('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
+sys.puts('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
\ No newline at end of file
diff --git a/package.json b/package.json
index 0d170d5..15df8fa 100644
--- a/package.json
+++ b/package.json
@@ -10,5 +10,7 @@
"engine": [
"node >=0.1.90"
],
- "main": "colors"
-}
\ No newline at end of file
+ "main": "colors" ,
+ "licenses": [{ "type": "MIT" }]
+ "contributers": ["Alexis Sellier", "Justin Campbell"]
+}