chalk 1.0.0 → 1.1.3

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.
Files changed (3) hide show
  1. package/index.js +31 -15
  2. package/package.json +28 -11
  3. package/readme.md +25 -9
package/index.js CHANGED
@@ -5,6 +5,7 @@ var stripAnsi = require('strip-ansi');
5
5
  var hasAnsi = require('has-ansi');
6
6
  var supportsColor = require('supports-color');
7
7
  var defineProps = Object.defineProperties;
8
+ var isSimpleWindowsTerm = process.platform === 'win32' && !/^xterm/i.test(process.env.TERM);
8
9
 
9
10
  function Chalk(options) {
10
11
  // detect mode if not set manually
@@ -12,22 +13,10 @@ function Chalk(options) {
12
13
  }
13
14
 
14
15
  // use bright blue on Windows as the normal blue color is illegible
15
- if (process.platform === 'win32') {
16
+ if (isSimpleWindowsTerm) {
16
17
  ansiStyles.blue.open = '\u001b[94m';
17
18
  }
18
19
 
19
- function build(_styles) {
20
- var builder = function builder() {
21
- return applyStyle.apply(builder, arguments);
22
- };
23
- builder._styles = _styles;
24
- builder.enabled = this.enabled;
25
- // __proto__ is used because we must return a function, but there is
26
- // no way to create a function with a different prototype.
27
- builder.__proto__ = proto;
28
- return builder;
29
- }
30
-
31
20
  var styles = (function () {
32
21
  var ret = {};
33
22
 
@@ -46,11 +35,27 @@ var styles = (function () {
46
35
 
47
36
  var proto = defineProps(function chalk() {}, styles);
48
37
 
38
+ function build(_styles) {
39
+ var builder = function () {
40
+ return applyStyle.apply(builder, arguments);
41
+ };
42
+
43
+ builder._styles = _styles;
44
+ builder.enabled = this.enabled;
45
+ // __proto__ is used because we must return a function, but there is
46
+ // no way to create a function with a different prototype.
47
+ /* eslint-disable no-proto */
48
+ builder.__proto__ = proto;
49
+
50
+ return builder;
51
+ }
52
+
49
53
  function applyStyle() {
50
54
  // support varags, but simply cast to string in case there's only one arg
51
55
  var args = arguments;
52
56
  var argsLen = args.length;
53
57
  var str = argsLen !== 0 && String(arguments[0]);
58
+
54
59
  if (argsLen > 1) {
55
60
  // don't slice `arguments`, it prevents v8 optimizations
56
61
  for (var a = 1; a < argsLen; a++) {
@@ -62,18 +67,29 @@ function applyStyle() {
62
67
  return str;
63
68
  }
64
69
 
65
- /*jshint validthis: true */
66
70
  var nestedStyles = this._styles;
67
-
68
71
  var i = nestedStyles.length;
72
+
73
+ // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
74
+ // see https://github.com/chalk/chalk/issues/58
75
+ // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
76
+ var originalDim = ansiStyles.dim.open;
77
+ if (isSimpleWindowsTerm && (nestedStyles.indexOf('gray') !== -1 || nestedStyles.indexOf('grey') !== -1)) {
78
+ ansiStyles.dim.open = '';
79
+ }
80
+
69
81
  while (i--) {
70
82
  var code = ansiStyles[nestedStyles[i]];
83
+
71
84
  // Replace any instances already present with a re-opening code
72
85
  // otherwise only the part of the string until said closing code
73
86
  // will be colored, and the rest will simply be 'plain'.
74
87
  str = code.open + str.replace(code.closeRe, code.open) + code.close;
75
88
  }
76
89
 
90
+ // Reset the original 'dim' if we changed it to work around the Windows dimmed gray issue.
91
+ ansiStyles.dim.open = originalDim;
92
+
77
93
  return str;
78
94
  }
79
95
 
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "chalk",
3
- "version": "1.0.0",
3
+ "version": "1.1.3",
4
4
  "description": "Terminal string styling done right. Much color.",
5
5
  "license": "MIT",
6
- "repository": "sindresorhus/chalk",
6
+ "repository": "chalk/chalk",
7
7
  "maintainers": [
8
- "Sindre Sorhus <sindresorhus@gmail.com> (http://sindresorhus.com)",
9
- "Joshua Appelman <jappelman@xebia.com> (http://jbnicolai.com)"
8
+ "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
9
+ "Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)",
10
+ "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
10
11
  ],
11
12
  "engines": {
12
13
  "node": ">=0.10.0"
13
14
  },
14
15
  "scripts": {
15
- "test": "mocha",
16
- "bench": "matcha benchmark.js"
16
+ "test": "xo && mocha",
17
+ "bench": "matcha benchmark.js",
18
+ "coverage": "nyc npm test && nyc report",
19
+ "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
17
20
  },
18
21
  "files": [
19
22
  "index.js"
@@ -26,7 +29,9 @@
26
29
  "console",
27
30
  "cli",
28
31
  "string",
32
+ "str",
29
33
  "ansi",
34
+ "style",
30
35
  "styles",
31
36
  "tty",
32
37
  "formatting",
@@ -40,14 +45,26 @@
40
45
  "text"
41
46
  ],
42
47
  "dependencies": {
43
- "ansi-styles": "^2.0.1",
48
+ "ansi-styles": "^2.2.1",
44
49
  "escape-string-regexp": "^1.0.2",
45
- "has-ansi": "^1.0.3",
46
- "strip-ansi": "^2.0.1",
47
- "supports-color": "^1.3.0"
50
+ "has-ansi": "^2.0.0",
51
+ "strip-ansi": "^3.0.0",
52
+ "supports-color": "^2.0.0"
48
53
  },
49
54
  "devDependencies": {
55
+ "coveralls": "^2.11.2",
50
56
  "matcha": "^0.6.0",
51
- "mocha": "*"
57
+ "mocha": "*",
58
+ "nyc": "^3.0.0",
59
+ "require-uncached": "^1.0.2",
60
+ "resolve-from": "^1.0.0",
61
+ "semver": "^4.3.3",
62
+ "xo": "*"
63
+ },
64
+ "xo": {
65
+ "envs": [
66
+ "node",
67
+ "mocha"
68
+ ]
52
69
  }
53
70
  }
package/readme.md CHANGED
@@ -1,19 +1,24 @@
1
1
  <h1 align="center">
2
2
  <br>
3
- <img width="360" src="https://cdn.rawgit.com/sindresorhus/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
3
+ <br>
4
+ <img width="360" src="https://cdn.rawgit.com/chalk/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
5
+ <br>
4
6
  <br>
5
7
  <br>
6
8
  </h1>
7
9
 
8
10
  > Terminal string styling done right
9
11
 
10
- [![Build Status](https://travis-ci.org/sindresorhus/chalk.svg?branch=master)](https://travis-ci.org/sindresorhus/chalk) [![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg?style=flat)](https://www.youtube.com/watch?v=Sm368W0OsHo)
12
+ [![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk)
13
+ [![Coverage Status](https://coveralls.io/repos/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/r/chalk/chalk?branch=master)
14
+ [![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4)
15
+
11
16
 
12
17
  [colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68). Although there are other ones, they either do too much or not enough.
13
18
 
14
19
  **Chalk is a clean and focused alternative.**
15
20
 
16
- ![screenshot](https://github.com/sindresorhus/ansi-styles/raw/master/screenshot.png)
21
+ ![](https://github.com/chalk/ansi-styles/raw/master/screenshot.png)
17
22
 
18
23
 
19
24
  ## Why
@@ -25,7 +30,7 @@
25
30
  - Clean and focused
26
31
  - Auto-detects color support
27
32
  - Actively maintained
28
- - [Used by ~3000 modules](https://www.npmjs.com/browse/depended/chalk)
33
+ - [Used by ~4500 modules](https://www.npmjs.com/browse/depended/chalk) as of July 15, 2015
29
34
 
30
35
 
31
36
  ## Install
@@ -104,13 +109,13 @@ var ctx = new chalk.constructor({enabled: false});
104
109
 
105
110
  ### chalk.supportsColor
106
111
 
107
- Detect whether the terminal [supports color](https://github.com/sindresorhus/supports-color). Used internally and handled for you, but exposed for convenience.
112
+ Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
108
113
 
109
114
  Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
110
115
 
111
116
  ### chalk.styles
112
117
 
113
- Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-styles).
118
+ Exposes the styles as [ANSI escape codes](https://github.com/chalk/ansi-styles).
114
119
 
115
120
  Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with your own.
116
121
 
@@ -125,11 +130,11 @@ console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
125
130
 
126
131
  ### chalk.hasColor(string)
127
132
 
128
- Check whether a string [has color](https://github.com/sindresorhus/has-ansi).
133
+ Check whether a string [has color](https://github.com/chalk/has-ansi).
129
134
 
130
135
  ### chalk.stripColor(string)
131
136
 
132
- [Strip color](https://github.com/sindresorhus/strip-ansi) from a string.
137
+ [Strip color](https://github.com/chalk/strip-ansi) from a string.
133
138
 
134
139
  Can be useful in combination with `.supportsColor` to strip color on externally styled text when it's not supported.
135
140
 
@@ -184,7 +189,7 @@ if (!chalk.supportsColor) {
184
189
 
185
190
  ## 256-colors
186
191
 
187
- Chalk does not support support anything other than the base eight colors, which guarantees it will work on all terminals and systems. Some terminals, specifically `xterm` compliant ones, will support the full range of 8-bit colors. For this the lower level [ansi-256-colors](https://github.com/jbnicolai/ansi-256-colors) package can be used.
192
+ Chalk does not support anything other than the base eight colors, which guarantees it will work on all terminals and systems. Some terminals, specifically `xterm` compliant ones, will support the full range of 8-bit colors. For this the lower level [ansi-256-colors](https://github.com/jbnicolai/ansi-256-colors) package can be used.
188
193
 
189
194
 
190
195
  ## Windows
@@ -192,6 +197,17 @@ Chalk does not support support anything other than the base eight colors, which
192
197
  If you're on Windows, do yourself a favor and use [`cmder`](http://bliker.github.io/cmder/) instead of `cmd.exe`.
193
198
 
194
199
 
200
+ ## Related
201
+
202
+ - [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
203
+ - [ansi-styles](https://github.com/chalk/ansi-styles/) - ANSI escape codes for styling strings in the terminal
204
+ - [supports-color](https://github.com/chalk/supports-color/) - Detect whether a terminal supports color
205
+ - [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
206
+ - [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
207
+ - [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
208
+ - [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
209
+
210
+
195
211
  ## License
196
212
 
197
213
  MIT © [Sindre Sorhus](http://sindresorhus.com)