colors 0.5.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIT-LICENSE.txt +4 -1
- package/ReadMe.md +58 -11
- package/colors.js +256 -144
- package/example.html +64 -8
- package/example.js +71 -14
- package/package.json +4 -1
- package/test.js +70 -0
- package/themes/winston-dark.js +12 -0
- package/themes/winston-light.js +12 -0
package/MIT-LICENSE.txt
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
Copyright (c) 2010
|
1
|
+
Copyright (c) 2010
|
2
|
+
|
3
|
+
Marak Squires
|
4
|
+
Alexis Sellier (cloudhead)
|
2
5
|
|
3
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/ReadMe.md
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
|
1
|
+
# colors.js - get color and style in your node.js console ( and browser ) like what
|
2
2
|
|
3
3
|
<img src="http://i.imgur.com/goJdO.png" border = "0"/>
|
4
4
|
|
5
|
-
var sys = require('sys');
|
6
|
-
var colors = require('./colors');
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
npm install colors
|
9
|
+
|
10
|
+
## colors and styles!
|
11
|
+
|
14
12
|
- bold
|
15
13
|
- italic
|
16
14
|
- underline
|
@@ -23,8 +21,57 @@
|
|
23
21
|
- red
|
24
22
|
- grey
|
25
23
|
- blue
|
24
|
+
- rainbow
|
25
|
+
- zebra
|
26
|
+
- random
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
``` js
|
31
|
+
var colors = require('./colors');
|
32
|
+
|
33
|
+
console.log('hello'.green); // outputs green text
|
34
|
+
console.log('i like cake and pies'.underline.red) // outputs red underlined text
|
35
|
+
console.log('inverse the color'.inverse); // inverses the color
|
36
|
+
console.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)
|
37
|
+
```
|
38
|
+
|
39
|
+
# Creating Custom themes
|
40
|
+
|
41
|
+
```js
|
42
|
+
|
43
|
+
var colors = require('colors');
|
44
|
+
|
45
|
+
colors.setTheme({
|
46
|
+
silly: 'rainbow',
|
47
|
+
input: 'grey',
|
48
|
+
verbose: 'cyan',
|
49
|
+
prompt: 'grey',
|
50
|
+
info: 'green',
|
51
|
+
data: 'grey',
|
52
|
+
help: 'cyan',
|
53
|
+
warn: 'yellow',
|
54
|
+
debug: 'blue',
|
55
|
+
error: 'red'
|
56
|
+
});
|
57
|
+
|
58
|
+
// outputs red text
|
59
|
+
console.log("this is an error".error);
|
60
|
+
|
61
|
+
// outputs yellow text
|
62
|
+
console.log("this is a warning".warn);
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
### Contributors
|
26
67
|
|
68
|
+
Marak (Marak Squires)
|
69
|
+
Alexis Sellier (cloudhead)
|
70
|
+
mmalecki (Maciej Małecki)
|
71
|
+
nicoreed (Nico Reed)
|
72
|
+
morganrallen (Morgan Allen)
|
73
|
+
JustinCampbell (Justin Campbell)
|
74
|
+
ded (Dustin Diaz)
|
27
75
|
|
28
|
-
### Authors
|
29
76
|
|
30
|
-
####
|
77
|
+
#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded)
|
package/colors.js
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
/*
|
2
2
|
colors.js
|
3
3
|
|
4
|
-
Copyright (c) 2010
|
4
|
+
Copyright (c) 2010
|
5
|
+
|
6
|
+
Marak Squires
|
7
|
+
Alexis Sellier (cloudhead)
|
5
8
|
|
6
9
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
10
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -23,81 +26,80 @@ THE SOFTWARE.
|
|
23
26
|
|
24
27
|
*/
|
25
28
|
|
26
|
-
|
29
|
+
var isHeadless = false;
|
27
30
|
|
28
|
-
|
31
|
+
if (typeof module !== 'undefined') {
|
32
|
+
isHeadless = true;
|
33
|
+
}
|
29
34
|
|
35
|
+
if (!isHeadless) {
|
36
|
+
var exports = {};
|
37
|
+
var module = {};
|
38
|
+
var colors = exports;
|
39
|
+
exports.mode = "browser";
|
40
|
+
} else {
|
41
|
+
exports.mode = "console";
|
42
|
+
}
|
43
|
+
|
44
|
+
//
|
45
|
+
// Prototypes the string object to have additional method calls that add terminal colors
|
46
|
+
//
|
30
47
|
var addProperty = function (color, func) {
|
31
|
-
exports[color] = function(str) {
|
48
|
+
exports[color] = function (str) {
|
32
49
|
return func.apply(str);
|
33
50
|
};
|
34
51
|
String.prototype.__defineGetter__(color, func);
|
35
|
-
}
|
52
|
+
};
|
36
53
|
|
37
|
-
|
38
|
-
['bold', 'underline', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'].forEach(function (style) {
|
54
|
+
function stylize(str, style) {
|
39
55
|
|
40
|
-
|
41
|
-
// http://robertnyman.com/javascript/javascript-getters-setters.html
|
42
|
-
// Object.defineProperty only works in Chrome
|
43
|
-
addProperty(style, function () {
|
44
|
-
return isHeadless ?
|
45
|
-
stylize(this, style) : // for those running in node (headless environments)
|
46
|
-
this.replace(/( )/, '$1'); // and for those running in browsers:
|
47
|
-
// re: ^ you'd think 'return this' works (but doesn't) so replace coerces the string to be a real string
|
48
|
-
});
|
49
|
-
});
|
56
|
+
var styles;
|
50
57
|
|
51
|
-
|
52
|
-
|
53
|
-
addProperty('rainbow', function () {
|
54
|
-
if (!isHeadless) {
|
55
|
-
return this.replace(/( )/, '$1');
|
56
|
-
}
|
57
|
-
var rainbowcolors = ['red','yellow','green','blue','magenta']; //RoY G BiV
|
58
|
-
var exploded = this.split("");
|
59
|
-
var i=0;
|
60
|
-
exploded = exploded.map(function(letter) {
|
61
|
-
if (letter==" ") {
|
62
|
-
return letter;
|
63
|
-
}
|
64
|
-
else {
|
65
|
-
return stylize(letter,rainbowcolors[i++ % rainbowcolors.length]);
|
66
|
-
}
|
67
|
-
});
|
68
|
-
return exploded.join("");
|
69
|
-
});
|
70
|
-
|
71
|
-
function stylize(str, style) {
|
72
|
-
if (exports.mode == 'console') {
|
73
|
-
var styles = {
|
58
|
+
if (exports.mode === 'console') {
|
59
|
+
styles = {
|
74
60
|
//styles
|
75
|
-
'bold' : ['\
|
76
|
-
'italic' : ['\
|
77
|
-
'underline' : ['\
|
78
|
-
'inverse' : ['\
|
61
|
+
'bold' : ['\x1B[1m', '\x1B[22m'],
|
62
|
+
'italic' : ['\x1B[3m', '\x1B[23m'],
|
63
|
+
'underline' : ['\x1B[4m', '\x1B[24m'],
|
64
|
+
'inverse' : ['\x1B[7m', '\x1B[27m'],
|
65
|
+
'strikethrough' : ['\x1B[9m', '\x1B[29m'],
|
66
|
+
//text colors
|
79
67
|
//grayscale
|
80
|
-
'white' : ['\
|
81
|
-
'grey' : ['\
|
82
|
-
'black' : ['\
|
68
|
+
'white' : ['\x1B[37m', '\x1B[39m'],
|
69
|
+
'grey' : ['\x1B[90m', '\x1B[39m'],
|
70
|
+
'black' : ['\x1B[30m', '\x1B[39m'],
|
83
71
|
//colors
|
84
|
-
'blue' : ['\
|
85
|
-
'cyan' : ['\
|
86
|
-
'green' : ['\
|
87
|
-
'magenta' : ['\
|
88
|
-
'red' : ['\
|
89
|
-
'yellow' : ['\
|
72
|
+
'blue' : ['\x1B[34m', '\x1B[39m'],
|
73
|
+
'cyan' : ['\x1B[36m', '\x1B[39m'],
|
74
|
+
'green' : ['\x1B[32m', '\x1B[39m'],
|
75
|
+
'magenta' : ['\x1B[35m', '\x1B[39m'],
|
76
|
+
'red' : ['\x1B[31m', '\x1B[39m'],
|
77
|
+
'yellow' : ['\x1B[33m', '\x1B[39m'],
|
78
|
+
//background colors
|
79
|
+
//grayscale
|
80
|
+
'whiteBG' : ['\x1B[47m', '\x1B[49m'],
|
81
|
+
'greyBG' : ['\x1B[49;5;8m', '\x1B[49m'],
|
82
|
+
'blackBG' : ['\x1B[40m', '\x1B[49m'],
|
83
|
+
//colors
|
84
|
+
'blueBG' : ['\x1B[44m', '\x1B[49m'],
|
85
|
+
'cyanBG' : ['\x1B[46m', '\x1B[49m'],
|
86
|
+
'greenBG' : ['\x1B[42m', '\x1B[49m'],
|
87
|
+
'magentaBG' : ['\x1B[45m', '\x1B[49m'],
|
88
|
+
'redBG' : ['\x1B[41m', '\x1B[49m'],
|
89
|
+
'yellowBG' : ['\x1B[43m', '\x1B[49m']
|
90
90
|
};
|
91
|
-
} else if (exports.mode
|
92
|
-
|
91
|
+
} else if (exports.mode === 'browser') {
|
92
|
+
styles = {
|
93
93
|
//styles
|
94
94
|
'bold' : ['<b>', '</b>'],
|
95
95
|
'italic' : ['<i>', '</i>'],
|
96
96
|
'underline' : ['<u>', '</u>'],
|
97
97
|
'inverse' : ['<span style="background-color:black;color:white;">', '</span>'],
|
98
|
+
'strikethrough' : ['<del>', '</del>'],
|
99
|
+
//text colors
|
98
100
|
//grayscale
|
99
101
|
'white' : ['<span style="color:white;">', '</span>'],
|
100
|
-
'grey' : ['<span style="color:
|
102
|
+
'grey' : ['<span style="color:gray;">', '</span>'],
|
101
103
|
'black' : ['<span style="color:black;">', '</span>'],
|
102
104
|
//colors
|
103
105
|
'blue' : ['<span style="color:blue;">', '</span>'],
|
@@ -105,126 +107,236 @@ function stylize(str, style) {
|
|
105
107
|
'green' : ['<span style="color:green;">', '</span>'],
|
106
108
|
'magenta' : ['<span style="color:magenta;">', '</span>'],
|
107
109
|
'red' : ['<span style="color:red;">', '</span>'],
|
108
|
-
'yellow' : ['<span style="color:yellow;">', '</span>']
|
110
|
+
'yellow' : ['<span style="color:yellow;">', '</span>'],
|
111
|
+
//background colors
|
112
|
+
//grayscale
|
113
|
+
'whiteBG' : ['<span style="background-color:white;">', '</span>'],
|
114
|
+
'greyBG' : ['<span style="background-color:gray;">', '</span>'],
|
115
|
+
'blackBG' : ['<span style="background-color:black;">', '</span>'],
|
116
|
+
//colors
|
117
|
+
'blueBG' : ['<span style="background-color:blue;">', '</span>'],
|
118
|
+
'cyanBG' : ['<span style="background-color:cyan;">', '</span>'],
|
119
|
+
'greenBG' : ['<span style="background-color:green;">', '</span>'],
|
120
|
+
'magentaBG' : ['<span style="background-color:magenta;">', '</span>'],
|
121
|
+
'redBG' : ['<span style="background-color:red;">', '</span>'],
|
122
|
+
'yellowBG' : ['<span style="background-color:yellow;">', '</span>']
|
109
123
|
};
|
110
|
-
} else if (exports.mode
|
111
|
-
|
124
|
+
} else if (exports.mode === 'none') {
|
125
|
+
return str + '';
|
112
126
|
} else {
|
113
127
|
console.log('unsupported mode, try "browser", "console" or "none"');
|
114
128
|
}
|
115
|
-
|
116
129
|
return styles[style][0] + str + styles[style][1];
|
130
|
+
}
|
131
|
+
|
132
|
+
function applyTheme(theme) {
|
133
|
+
|
134
|
+
//
|
135
|
+
// Remark: This is a list of methods that exist
|
136
|
+
// on String that you should not overwrite.
|
137
|
+
//
|
138
|
+
var stringPrototypeBlacklist = [
|
139
|
+
'__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
|
140
|
+
'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
|
141
|
+
'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring',
|
142
|
+
'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight'
|
143
|
+
];
|
144
|
+
|
145
|
+
Object.keys(theme).forEach(function (prop) {
|
146
|
+
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
|
147
|
+
console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name');
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
if (typeof(theme[prop]) === 'string') {
|
151
|
+
addProperty(prop, function () {
|
152
|
+
return exports[theme[prop]](this);
|
153
|
+
});
|
154
|
+
}
|
155
|
+
else {
|
156
|
+
addProperty(prop, function () {
|
157
|
+
var ret = this;
|
158
|
+
for (var t = 0; t < theme[prop].length; t++) {
|
159
|
+
ret = exports[theme[prop][t]](ret);
|
160
|
+
}
|
161
|
+
return ret;
|
162
|
+
});
|
163
|
+
}
|
164
|
+
}
|
165
|
+
});
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
//
|
170
|
+
// Iterate through all default styles and colors
|
171
|
+
//
|
172
|
+
var x = ['bold', 'underline', 'strikethrough', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta', 'greyBG', 'blackBG', 'yellowBG', 'redBG', 'greenBG', 'blueBG', 'whiteBG', 'cyanBG', 'magentaBG'];
|
173
|
+
x.forEach(function (style) {
|
174
|
+
|
175
|
+
// __defineGetter__ at the least works in more browsers
|
176
|
+
// http://robertnyman.com/javascript/javascript-getters-setters.html
|
177
|
+
// Object.defineProperty only works in Chrome
|
178
|
+
addProperty(style, function () {
|
179
|
+
return stylize(this, style);
|
180
|
+
});
|
181
|
+
});
|
182
|
+
|
183
|
+
function sequencer(map) {
|
184
|
+
return function () {
|
185
|
+
if (!isHeadless) {
|
186
|
+
return this.replace(/( )/, '$1');
|
187
|
+
}
|
188
|
+
var exploded = this.split(""), i = 0;
|
189
|
+
exploded = exploded.map(map);
|
190
|
+
return exploded.join("");
|
191
|
+
};
|
192
|
+
}
|
193
|
+
|
194
|
+
var rainbowMap = (function () {
|
195
|
+
var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV
|
196
|
+
return function (letter, i, exploded) {
|
197
|
+
if (letter === " ") {
|
198
|
+
return letter;
|
199
|
+
} else {
|
200
|
+
return stylize(letter, rainbowColors[i++ % rainbowColors.length]);
|
201
|
+
}
|
202
|
+
};
|
203
|
+
})();
|
204
|
+
|
205
|
+
exports.themes = {};
|
206
|
+
|
207
|
+
exports.addSequencer = function (name, map) {
|
208
|
+
addProperty(name, sequencer(map));
|
117
209
|
};
|
118
210
|
|
119
|
-
|
120
|
-
|
121
|
-
return
|
211
|
+
exports.addSequencer('rainbow', rainbowMap);
|
212
|
+
exports.addSequencer('zebra', function (letter, i, exploded) {
|
213
|
+
return i % 2 === 0 ? letter : letter.inverse;
|
214
|
+
});
|
215
|
+
|
216
|
+
exports.setTheme = function (theme) {
|
217
|
+
if (typeof theme === 'string') {
|
218
|
+
try {
|
219
|
+
exports.themes[theme] = require(theme);
|
220
|
+
applyTheme(exports.themes[theme]);
|
221
|
+
return exports.themes[theme];
|
222
|
+
} catch (err) {
|
223
|
+
console.log(err);
|
224
|
+
return err;
|
225
|
+
}
|
226
|
+
} else {
|
227
|
+
applyTheme(theme);
|
228
|
+
}
|
229
|
+
};
|
230
|
+
|
231
|
+
|
232
|
+
addProperty('stripColors', function () {
|
233
|
+
return ("" + this).replace(/\x1B\[\d+m/g, '');
|
122
234
|
});
|
123
235
|
|
124
236
|
// please no
|
125
237
|
function zalgo(text, options) {
|
126
238
|
var soul = {
|
127
239
|
"up" : [
|
128
|
-
'̍','̎','̄','̅',
|
129
|
-
'̿','̑','̆','̐',
|
130
|
-
'͒','͗','͑','̇',
|
131
|
-
'̈','̊','͂','̓',
|
132
|
-
'̈','͊','͋','͌',
|
133
|
-
'̃','̂','̌','͐',
|
134
|
-
'̀','́','̋','̏',
|
135
|
-
'̒','̓','̔','̽',
|
136
|
-
'̉','ͣ','ͤ','ͥ',
|
137
|
-
'ͦ','ͧ','ͨ','ͩ',
|
138
|
-
'ͪ','ͫ','ͬ','ͭ',
|
139
|
-
'ͮ','ͯ','̾','͛',
|
140
|
-
'͆','̚'
|
141
|
-
|
240
|
+
'̍', '̎', '̄', '̅',
|
241
|
+
'̿', '̑', '̆', '̐',
|
242
|
+
'͒', '͗', '͑', '̇',
|
243
|
+
'̈', '̊', '͂', '̓',
|
244
|
+
'̈', '͊', '͋', '͌',
|
245
|
+
'̃', '̂', '̌', '͐',
|
246
|
+
'̀', '́', '̋', '̏',
|
247
|
+
'̒', '̓', '̔', '̽',
|
248
|
+
'̉', 'ͣ', 'ͤ', 'ͥ',
|
249
|
+
'ͦ', 'ͧ', 'ͨ', 'ͩ',
|
250
|
+
'ͪ', 'ͫ', 'ͬ', 'ͭ',
|
251
|
+
'ͮ', 'ͯ', '̾', '͛',
|
252
|
+
'͆', '̚'
|
253
|
+
],
|
142
254
|
"down" : [
|
143
|
-
'̖','̗','̘','̙',
|
144
|
-
'̜','̝','̞','̟',
|
145
|
-
'̠','̤','̥','̦',
|
146
|
-
'̩','̪','̫','̬',
|
147
|
-
'̭','̮','̯','̰',
|
148
|
-
'̱','̲','̳','̹',
|
149
|
-
'̺','̻','̼','ͅ',
|
150
|
-
'͇','͈','͉','͍',
|
151
|
-
'͎','͓','͔','͕',
|
152
|
-
'͖','͙','͚','̣'
|
153
|
-
|
255
|
+
'̖', '̗', '̘', '̙',
|
256
|
+
'̜', '̝', '̞', '̟',
|
257
|
+
'̠', '̤', '̥', '̦',
|
258
|
+
'̩', '̪', '̫', '̬',
|
259
|
+
'̭', '̮', '̯', '̰',
|
260
|
+
'̱', '̲', '̳', '̹',
|
261
|
+
'̺', '̻', '̼', 'ͅ',
|
262
|
+
'͇', '͈', '͉', '͍',
|
263
|
+
'͎', '͓', '͔', '͕',
|
264
|
+
'͖', '͙', '͚', '̣'
|
265
|
+
],
|
154
266
|
"mid" : [
|
155
|
-
'̕','̛','̀','́',
|
156
|
-
'͘','̡','̢','̧',
|
157
|
-
'̨','̴','̵','̶',
|
158
|
-
'͜','͝','͞',
|
159
|
-
'͟','͠','͢','̸',
|
160
|
-
'̷','͡',' ҉'
|
161
|
-
|
267
|
+
'̕', '̛', '̀', '́',
|
268
|
+
'͘', '̡', '̢', '̧',
|
269
|
+
'̨', '̴', '̵', '̶',
|
270
|
+
'͜', '͝', '͞',
|
271
|
+
'͟', '͠', '͢', '̸',
|
272
|
+
'̷', '͡', ' ҉'
|
273
|
+
]
|
162
274
|
},
|
163
275
|
all = [].concat(soul.up, soul.down, soul.mid),
|
164
276
|
zalgo = {};
|
165
277
|
|
166
278
|
function randomNumber(range) {
|
167
|
-
r = Math.floor(Math.random()*range);
|
279
|
+
var r = Math.floor(Math.random() * range);
|
168
280
|
return r;
|
169
|
-
}
|
281
|
+
}
|
170
282
|
|
171
283
|
function is_char(character) {
|
172
284
|
var bool = false;
|
173
|
-
all.filter(function(i){
|
174
|
-
|
285
|
+
all.filter(function (i) {
|
286
|
+
bool = (i === character);
|
175
287
|
});
|
176
288
|
return bool;
|
177
289
|
}
|
178
290
|
|
179
|
-
function heComes(text, options){
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
}
|
291
|
+
function heComes(text, options) {
|
292
|
+
var result = '', counts, l;
|
293
|
+
options = options || {};
|
294
|
+
options["up"] = options["up"] || true;
|
295
|
+
options["mid"] = options["mid"] || true;
|
296
|
+
options["down"] = options["down"] || true;
|
297
|
+
options["size"] = options["size"] || "maxi";
|
298
|
+
text = text.split('');
|
299
|
+
for (l in text) {
|
300
|
+
if (is_char(l)) {
|
301
|
+
continue;
|
302
|
+
}
|
303
|
+
result = result + text[l];
|
304
|
+
counts = {"up" : 0, "down" : 0, "mid" : 0};
|
305
|
+
switch (options.size) {
|
306
|
+
case 'mini':
|
307
|
+
counts.up = randomNumber(8);
|
308
|
+
counts.min = randomNumber(2);
|
309
|
+
counts.down = randomNumber(8);
|
310
|
+
break;
|
311
|
+
case 'maxi':
|
312
|
+
counts.up = randomNumber(16) + 3;
|
313
|
+
counts.min = randomNumber(4) + 1;
|
314
|
+
counts.down = randomNumber(64) + 3;
|
315
|
+
break;
|
316
|
+
default:
|
317
|
+
counts.up = randomNumber(8) + 1;
|
318
|
+
counts.mid = randomNumber(6) / 2;
|
319
|
+
counts.down = randomNumber(8) + 1;
|
320
|
+
break;
|
321
|
+
}
|
211
322
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
{
|
217
|
-
|
218
|
-
result = result + soul[index][randomNumber(soul[index].length)];
|
219
|
-
}
|
220
|
-
}
|
323
|
+
var arr = ["up", "mid", "down"];
|
324
|
+
for (var d in arr) {
|
325
|
+
var index = arr[d];
|
326
|
+
for (var i = 0 ; i <= counts[index]; i++) {
|
327
|
+
if (options[index]) {
|
328
|
+
result = result + soul[index][randomNumber(soul[index].length)];
|
221
329
|
}
|
222
330
|
}
|
223
|
-
|
224
|
-
|
331
|
+
}
|
332
|
+
}
|
333
|
+
return result;
|
334
|
+
}
|
225
335
|
return heComes(text);
|
226
336
|
}
|
227
337
|
|
228
|
-
|
229
|
-
|
338
|
+
|
339
|
+
// don't summon zalgo
|
340
|
+
addProperty('zalgo', function () {
|
341
|
+
return zalgo(this);
|
230
342
|
});
|
package/example.html
CHANGED
@@ -4,17 +4,73 @@
|
|
4
4
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
5
5
|
<title>Colors Example</title>
|
6
6
|
<script src="colors.js"></script>
|
7
|
-
<script type="text/javascript">
|
8
|
-
console.log('Rainbows are fun!'.rainbow);
|
9
|
-
console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse);
|
10
|
-
console.log('Chains are also cool.'.bold.italic.underline.red);
|
11
|
-
</script>
|
12
7
|
</head>
|
13
8
|
<body>
|
14
9
|
<script>
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
|
11
|
+
var test = colors.red("hopefully colorless output");
|
12
|
+
|
13
|
+
document.write('Rainbows are fun!'.rainbow + '<br/>');
|
14
|
+
document.write('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
|
15
|
+
document.write('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
16
|
+
//document.write('zalgo time!'.zalgo);
|
17
|
+
document.write(test.stripColors);
|
18
|
+
document.write("a".grey + " b".black);
|
19
|
+
|
20
|
+
document.write("Zebras are so fun!".zebra);
|
21
|
+
|
22
|
+
document.write(colors.rainbow('Rainbows are fun!'));
|
23
|
+
document.write("This is " + "not".strikethrough + " fun.");
|
24
|
+
|
25
|
+
document.write(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
26
|
+
document.write(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
27
|
+
//document.write(colors.zalgo('zalgo time!'));
|
28
|
+
document.write(colors.stripColors(test));
|
29
|
+
document.write(colors.grey("a") + colors.black(" b"));
|
30
|
+
|
31
|
+
colors.addSequencer("america", function(letter, i, exploded) {
|
32
|
+
if(letter === " ") return letter;
|
33
|
+
switch(i%3) {
|
34
|
+
case 0: return letter.red;
|
35
|
+
case 1: return letter.white;
|
36
|
+
case 2: return letter.blue;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
|
40
|
+
colors.addSequencer("random", (function() {
|
41
|
+
var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
42
|
+
|
43
|
+
return function(letter, i, exploded) {
|
44
|
+
return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
|
45
|
+
};
|
46
|
+
})());
|
47
|
+
|
48
|
+
document.write("AMERICA! F--K YEAH!".america);
|
49
|
+
document.write("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
|
50
|
+
|
51
|
+
//
|
52
|
+
// Custom themes
|
53
|
+
//
|
54
|
+
|
55
|
+
colors.setTheme({
|
56
|
+
silly: 'rainbow',
|
57
|
+
input: 'grey',
|
58
|
+
verbose: 'cyan',
|
59
|
+
prompt: 'grey',
|
60
|
+
info: 'green',
|
61
|
+
data: 'grey',
|
62
|
+
help: 'cyan',
|
63
|
+
warn: 'yellow',
|
64
|
+
debug: 'blue',
|
65
|
+
error: 'red'
|
66
|
+
});
|
67
|
+
|
68
|
+
// outputs red text
|
69
|
+
document.write("this is an error".error);
|
70
|
+
|
71
|
+
// outputs yellow text
|
72
|
+
document.write("this is a warning".warn);
|
73
|
+
|
18
74
|
</script>
|
19
75
|
</body>
|
20
76
|
</html>
|
package/example.js
CHANGED
@@ -1,20 +1,77 @@
|
|
1
|
-
var util = require('util');
|
2
1
|
var colors = require('./colors');
|
3
2
|
|
4
3
|
//colors.mode = "browser";
|
5
4
|
|
6
5
|
var test = colors.red("hopefully colorless output");
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
//
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
//
|
18
|
-
|
19
|
-
|
6
|
+
console.log('Rainbows are fun!'.rainbow);
|
7
|
+
console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported
|
8
|
+
console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
9
|
+
//console.log('zalgo time!'.zalgo);
|
10
|
+
console.log(test.stripColors);
|
11
|
+
console.log("a".grey + " b".black);
|
12
|
+
console.log("Zebras are so fun!".zebra);
|
13
|
+
console.log('background color attack!'.black.whiteBG)
|
14
|
+
|
15
|
+
//
|
16
|
+
// Remark: .strikethrough may not work with Mac OS Terminal App
|
17
|
+
//
|
18
|
+
console.log("This is " + "not".strikethrough + " fun.");
|
19
|
+
console.log(colors.rainbow('Rainbows are fun!'));
|
20
|
+
console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported
|
21
|
+
console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported
|
22
|
+
//console.log(colors.zalgo('zalgo time!'));
|
23
|
+
console.log(colors.stripColors(test));
|
24
|
+
console.log(colors.grey("a") + colors.black(" b"));
|
25
|
+
|
26
|
+
colors.addSequencer("america", function(letter, i, exploded) {
|
27
|
+
if(letter === " ") return letter;
|
28
|
+
switch(i%3) {
|
29
|
+
case 0: return letter.red;
|
30
|
+
case 1: return letter.white;
|
31
|
+
case 2: return letter.blue;
|
32
|
+
}
|
33
|
+
});
|
34
|
+
|
35
|
+
colors.addSequencer("random", (function() {
|
36
|
+
var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'];
|
37
|
+
|
38
|
+
return function(letter, i, exploded) {
|
39
|
+
return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]];
|
40
|
+
};
|
41
|
+
})());
|
42
|
+
|
43
|
+
console.log("AMERICA! F--K YEAH!".america);
|
44
|
+
console.log("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random);
|
45
|
+
|
46
|
+
//
|
47
|
+
// Custom themes
|
48
|
+
//
|
49
|
+
|
50
|
+
// Load theme with JSON literal
|
51
|
+
colors.setTheme({
|
52
|
+
silly: 'rainbow',
|
53
|
+
input: 'grey',
|
54
|
+
verbose: 'cyan',
|
55
|
+
prompt: 'grey',
|
56
|
+
info: 'green',
|
57
|
+
data: 'grey',
|
58
|
+
help: 'cyan',
|
59
|
+
warn: 'yellow',
|
60
|
+
debug: 'blue',
|
61
|
+
error: 'red'
|
62
|
+
});
|
63
|
+
|
64
|
+
// outputs red text
|
65
|
+
console.log("this is an error".error);
|
66
|
+
|
67
|
+
// outputs yellow text
|
68
|
+
console.log("this is a warning".warn);
|
69
|
+
|
70
|
+
// outputs grey text
|
71
|
+
console.log("this is an input".input);
|
72
|
+
|
73
|
+
// Load a theme from file
|
74
|
+
colors.setTheme('./themes/winston-dark.js');
|
75
|
+
|
76
|
+
console.log("this is an input".input);
|
20
77
|
|
package/package.json
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "colors",
|
3
3
|
"description": "get colors in your node.js console like what",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.6.2",
|
5
5
|
"author": "Marak Squires",
|
6
|
+
"homepage": "https://github.com/Marak/colors.js",
|
7
|
+
"bugs": "https://github.com/Marak/colors.js/issues",
|
8
|
+
"keywords": [ "ansi", "terminal", "colors" ],
|
6
9
|
"repository": {
|
7
10
|
"type": "git",
|
8
11
|
"url": "http://github.com/Marak/colors.js.git"
|
package/test.js
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
var assert = require('assert'),
|
2
|
+
colors = require('./colors');
|
3
|
+
|
4
|
+
var s = 'string';
|
5
|
+
|
6
|
+
function a(s, code) {
|
7
|
+
return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m';
|
8
|
+
}
|
9
|
+
|
10
|
+
function aE(s, color, code) {
|
11
|
+
assert.equal(s[color], a(s, code));
|
12
|
+
assert.equal(colors[color](s), a(s, code));
|
13
|
+
assert.equal(s[color], colors[color](s));
|
14
|
+
assert.equal(s[color].stripColors, s);
|
15
|
+
assert.equal(s[color].stripColors, colors.stripColors(s));
|
16
|
+
}
|
17
|
+
|
18
|
+
function h(s, color) {
|
19
|
+
return '<span style="color:' + color + ';">' + s + '</span>';
|
20
|
+
}
|
21
|
+
|
22
|
+
var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
|
23
|
+
var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
|
24
|
+
|
25
|
+
colors.mode = 'console';
|
26
|
+
assert.equal(s.bold, '\x1B[1m' + s + '\x1B[22m');
|
27
|
+
assert.equal(s.italic, '\x1B[3m' + s + '\x1B[23m');
|
28
|
+
assert.equal(s.underline, '\x1B[4m' + s + '\x1B[24m');
|
29
|
+
assert.equal(s.strikethrough, '\x1B[9m' + s + '\x1B[29m');
|
30
|
+
assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m');
|
31
|
+
assert.ok(s.rainbow);
|
32
|
+
aE(s, 'white', 37);
|
33
|
+
aE(s, 'grey', 90);
|
34
|
+
aE(s, 'black', 30);
|
35
|
+
aE(s, 'blue', 34);
|
36
|
+
aE(s, 'cyan', 36);
|
37
|
+
aE(s, 'green', 32);
|
38
|
+
aE(s, 'magenta', 35);
|
39
|
+
aE(s, 'red', 31);
|
40
|
+
aE(s, 'yellow', 33);
|
41
|
+
assert.equal(s, 'string');
|
42
|
+
|
43
|
+
colors.setTheme({error:'red'});
|
44
|
+
|
45
|
+
assert.equal(typeof("astring".red),'string');
|
46
|
+
assert.equal(typeof("astring".error),'string');
|
47
|
+
|
48
|
+
colors.mode = 'browser';
|
49
|
+
assert.equal(s.bold, '<b>' + s + '</b>');
|
50
|
+
assert.equal(s.italic, '<i>' + s + '</i>');
|
51
|
+
assert.equal(s.underline, '<u>' + s + '</u>');
|
52
|
+
assert.equal(s.strikethrough, '<del>' + s + '</del>');
|
53
|
+
assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
|
54
|
+
assert.ok(s.rainbow);
|
55
|
+
stylesColors.forEach(function (color) {
|
56
|
+
assert.equal(s[color], h(s, color));
|
57
|
+
assert.equal(colors[color](s), h(s, color));
|
58
|
+
});
|
59
|
+
|
60
|
+
assert.equal(typeof("astring".red),'string');
|
61
|
+
assert.equal(typeof("astring".error),'string');
|
62
|
+
|
63
|
+
colors.mode = 'none';
|
64
|
+
stylesAll.forEach(function (style) {
|
65
|
+
assert.equal(s[style], s);
|
66
|
+
assert.equal(colors[style](s), s);
|
67
|
+
});
|
68
|
+
|
69
|
+
assert.equal(typeof("astring".red),'string');
|
70
|
+
assert.equal(typeof("astring".error),'string');
|