colors 1.3.3 → 1.4.0
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/README.md +39 -2
- package/examples/normal-usage.js +1 -0
- package/examples/safe-string.js +2 -0
- package/lib/colors.js +12 -2
- package/lib/maps/random.js +2 -1
- package/lib/styles.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
@@ -29,6 +29,16 @@ Please check out the [roadmap](ROADMAP.md) for upcoming features and releases.
|
|
29
29
|
- gray
|
30
30
|
- grey
|
31
31
|
|
32
|
+
### bright text colors
|
33
|
+
|
34
|
+
- brightRed
|
35
|
+
- brightGreen
|
36
|
+
- brightYellow
|
37
|
+
- brightBlue
|
38
|
+
- brightMagenta
|
39
|
+
- brightCyan
|
40
|
+
- brightWhite
|
41
|
+
|
32
42
|
### background colors
|
33
43
|
|
34
44
|
- bgBlack
|
@@ -39,6 +49,18 @@ Please check out the [roadmap](ROADMAP.md) for upcoming features and releases.
|
|
39
49
|
- bgMagenta
|
40
50
|
- bgCyan
|
41
51
|
- bgWhite
|
52
|
+
- bgGray
|
53
|
+
- bgGrey
|
54
|
+
|
55
|
+
### bright background colors
|
56
|
+
|
57
|
+
- bgBrightRed
|
58
|
+
- bgBrightGreen
|
59
|
+
- bgBrightYellow
|
60
|
+
- bgBrightBlue
|
61
|
+
- bgBrightMagenta
|
62
|
+
- bgBrightCyan
|
63
|
+
- bgBrightWhite
|
42
64
|
|
43
65
|
### styles
|
44
66
|
|
@@ -94,12 +116,27 @@ I prefer the first way. Some people seem to be afraid of extending `String.proto
|
|
94
116
|
|
95
117
|
If you are writing good code you will never have an issue with the first approach. If you really don't want to touch `String.prototype`, the second usage will not touch `String` native object.
|
96
118
|
|
97
|
-
## Disabling Colors
|
119
|
+
## Enabling/Disabling Colors
|
98
120
|
|
99
|
-
|
121
|
+
The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:
|
100
122
|
|
101
123
|
```bash
|
102
124
|
node myapp.js --no-color
|
125
|
+
node myapp.js --color=false
|
126
|
+
|
127
|
+
node myapp.js --color
|
128
|
+
node myapp.js --color=true
|
129
|
+
node myapp.js --color=always
|
130
|
+
|
131
|
+
FORCE_COLOR=1 node myapp.js
|
132
|
+
```
|
133
|
+
|
134
|
+
Or in code:
|
135
|
+
|
136
|
+
```javascript
|
137
|
+
var colors = require('colors');
|
138
|
+
colors.enable();
|
139
|
+
colors.disable();
|
103
140
|
```
|
104
141
|
|
105
142
|
## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data)
|
package/examples/normal-usage.js
CHANGED
@@ -29,6 +29,7 @@ console.log('Background color attack!'.black.bgWhite);
|
|
29
29
|
console.log('Use random styles on everything!'.random);
|
30
30
|
console.log('America, Heck Yeah!'.america);
|
31
31
|
|
32
|
+
console.log('Blindingly '.brightCyan + 'bright? '.brightRed + 'Why '.brightYellow + 'not?!'.brightGreen);
|
32
33
|
|
33
34
|
console.log('Setting themes is useful');
|
34
35
|
|
package/examples/safe-string.js
CHANGED
@@ -28,6 +28,8 @@ console.log(colors.black.bgWhite('Background color attack!'));
|
|
28
28
|
console.log(colors.random('Use random styles on everything!'));
|
29
29
|
console.log(colors.america('America, Heck Yeah!'));
|
30
30
|
|
31
|
+
console.log(colors.brightCyan('Blindingly ') + colors.brightRed('bright? ') + colors.brightYellow('Why ') + colors.brightGreen('not?!'));
|
32
|
+
|
31
33
|
console.log('Setting themes is useful');
|
32
34
|
|
33
35
|
//
|
package/lib/colors.js
CHANGED
@@ -62,7 +62,16 @@ var stylize = colors.stylize = function stylize(str, style) {
|
|
62
62
|
return str+'';
|
63
63
|
}
|
64
64
|
|
65
|
-
|
65
|
+
var styleMap = ansiStyles[style];
|
66
|
+
|
67
|
+
// Stylize should work for non-ANSI styles, too
|
68
|
+
if(!styleMap && style in colors){
|
69
|
+
// Style maps like trap operate as functions on strings;
|
70
|
+
// they don't have properties like open or close.
|
71
|
+
return colors[style](str);
|
72
|
+
}
|
73
|
+
|
74
|
+
return styleMap.open + str + styleMap.close;
|
66
75
|
};
|
67
76
|
|
68
77
|
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
@@ -105,7 +114,8 @@ function applyStyle() {
|
|
105
114
|
var args = Array.prototype.slice.call(arguments);
|
106
115
|
|
107
116
|
var str = args.map(function(arg) {
|
108
|
-
|
117
|
+
// Use weak equality check so we can colorize null/undefined in safe mode
|
118
|
+
if (arg != null && arg.constructor === String) {
|
109
119
|
return arg;
|
110
120
|
} else {
|
111
121
|
return util.inspect(arg);
|
package/lib/maps/random.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module['exports'] = function(colors) {
|
2
2
|
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
|
3
|
-
'blue', 'white', 'cyan', 'magenta'
|
3
|
+
'blue', 'white', 'cyan', 'magenta', 'brightYellow', 'brightRed',
|
4
|
+
'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan', 'brightMagenta'];
|
4
5
|
return function(letter, i, exploded) {
|
5
6
|
return letter === ' ' ? letter :
|
6
7
|
colors[
|
package/lib/styles.js
CHANGED
@@ -48,6 +48,14 @@ var codes = {
|
|
48
48
|
gray: [90, 39],
|
49
49
|
grey: [90, 39],
|
50
50
|
|
51
|
+
brightRed: [91, 39],
|
52
|
+
brightGreen: [92, 39],
|
53
|
+
brightYellow: [93, 39],
|
54
|
+
brightBlue: [94, 39],
|
55
|
+
brightMagenta: [95, 39],
|
56
|
+
brightCyan: [96, 39],
|
57
|
+
brightWhite: [97, 39],
|
58
|
+
|
51
59
|
bgBlack: [40, 49],
|
52
60
|
bgRed: [41, 49],
|
53
61
|
bgGreen: [42, 49],
|
@@ -56,6 +64,16 @@ var codes = {
|
|
56
64
|
bgMagenta: [45, 49],
|
57
65
|
bgCyan: [46, 49],
|
58
66
|
bgWhite: [47, 49],
|
67
|
+
bgGray: [100, 49],
|
68
|
+
bgGrey: [100, 49],
|
69
|
+
|
70
|
+
bgBrightRed: [101, 49],
|
71
|
+
bgBrightGreen: [102, 49],
|
72
|
+
bgBrightYellow: [103, 49],
|
73
|
+
bgBrightBlue: [104, 49],
|
74
|
+
bgBrightMagenta: [105, 49],
|
75
|
+
bgBrightCyan: [106, 49],
|
76
|
+
bgBrightWhite: [107, 49],
|
59
77
|
|
60
78
|
// legacy styles for colors pre v1.0.0
|
61
79
|
blackBG: [40, 49],
|