[Pkg-javascript-commits] [node-chalk] 01/12: Imported Upstream version 1.1.3
Mathias Behrle
mbehrle at moszumanska.debian.org
Sat Jul 23 13:39:55 UTC 2016
This is an automated email from the git hooks/post-receive script.
mbehrle pushed a commit to branch master
in repository node-chalk.
commit e540a40bbddc03701eb413bba55e6931d6b27ab8
Author: Mathias Behrle <mathiasb at m9s.biz>
Date: Mon Jul 18 17:36:51 2016 +0200
Imported Upstream version 1.1.3
---
.editorconfig | 2 +-
.gitignore | 2 ++
.jshintrc | 13 ----------
.travis.yml | 1 +
benchmark.js | 2 ++
index.js | 46 ++++++++++++++++++++++-----------
logo.png => media/logo.png | Bin
logo.svg => media/logo.svg | 0
package.json | 39 ++++++++++++++++++++--------
readme.md | 34 +++++++++++++++++-------
test.js | 63 ++++++++++++++++++++++++++++++++++++++++++++-
11 files changed, 152 insertions(+), 50 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 86c8f59..8f9d77e 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,7 +7,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
-[package.json]
+[{package.json,*.yml}]
indent_style = space
indent_size = 2
diff --git a/.gitignore b/.gitignore
index 3c3629e..1fd04da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
node_modules
+coverage
+.nyc_output
diff --git a/.jshintrc b/.jshintrc
deleted file mode 100644
index 804f8af..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "node": true,
- "esnext": true,
- "bitwise": true,
- "camelcase": true,
- "curly": true,
- "immed": true,
- "newcap": true,
- "noarg": true,
- "undef": true,
- "unused": "vars",
- "strict": true
-}
diff --git a/.travis.yml b/.travis.yml
index dedfc07..3da5271 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,3 +4,4 @@ node_js:
- 'iojs'
- '0.12'
- '0.10'
+after_success: npm run coveralls
diff --git a/benchmark.js b/benchmark.js
index ce3f2c4..5c26a87 100644
--- a/benchmark.js
+++ b/benchmark.js
@@ -1,3 +1,5 @@
+/* globals set bench */
+'use strict';
var chalk = require('./');
suite('chalk', function () {
diff --git a/index.js b/index.js
index 4138a64..2d85a91 100644
--- a/index.js
+++ b/index.js
@@ -5,6 +5,7 @@ var stripAnsi = require('strip-ansi');
var hasAnsi = require('has-ansi');
var supportsColor = require('supports-color');
var defineProps = Object.defineProperties;
+var isSimpleWindowsTerm = process.platform === 'win32' && !/^xterm/i.test(process.env.TERM);
function Chalk(options) {
// detect mode if not set manually
@@ -12,22 +13,10 @@ function Chalk(options) {
}
// use bright blue on Windows as the normal blue color is illegible
-if (process.platform === 'win32') {
+if (isSimpleWindowsTerm) {
ansiStyles.blue.open = '\u001b[94m';
}
-function build(_styles) {
- var builder = function builder() {
- return applyStyle.apply(builder, arguments);
- };
- builder._styles = _styles;
- builder.enabled = this.enabled;
- // __proto__ is used because we must return a function, but there is
- // no way to create a function with a different prototype.
- builder.__proto__ = proto;
- return builder;
-}
-
var styles = (function () {
var ret = {};
@@ -46,11 +35,27 @@ var styles = (function () {
var proto = defineProps(function chalk() {}, styles);
+function build(_styles) {
+ var builder = function () {
+ return applyStyle.apply(builder, arguments);
+ };
+
+ builder._styles = _styles;
+ builder.enabled = this.enabled;
+ // __proto__ is used because we must return a function, but there is
+ // no way to create a function with a different prototype.
+ /* eslint-disable no-proto */
+ builder.__proto__ = proto;
+
+ return builder;
+}
+
function applyStyle() {
// support varags, but simply cast to string in case there's only one arg
var args = arguments;
var argsLen = args.length;
var str = argsLen !== 0 && String(arguments[0]);
+
if (argsLen > 1) {
// don't slice `arguments`, it prevents v8 optimizations
for (var a = 1; a < argsLen; a++) {
@@ -62,18 +67,29 @@ function applyStyle() {
return str;
}
- /*jshint validthis: true */
var nestedStyles = this._styles;
-
var i = nestedStyles.length;
+
+ // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
+ // see https://github.com/chalk/chalk/issues/58
+ // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
+ var originalDim = ansiStyles.dim.open;
+ if (isSimpleWindowsTerm && (nestedStyles.indexOf('gray') !== -1 || nestedStyles.indexOf('grey') !== -1)) {
+ ansiStyles.dim.open = '';
+ }
+
while (i--) {
var code = ansiStyles[nestedStyles[i]];
+
// Replace any instances already present with a re-opening code
// otherwise only the part of the string until said closing code
// will be colored, and the rest will simply be 'plain'.
str = code.open + str.replace(code.closeRe, code.open) + code.close;
}
+ // Reset the original 'dim' if we changed it to work around the Windows dimmed gray issue.
+ ansiStyles.dim.open = originalDim;
+
return str;
}
diff --git a/logo.png b/media/logo.png
similarity index 100%
rename from logo.png
rename to media/logo.png
diff --git a/logo.svg b/media/logo.svg
similarity index 100%
rename from logo.svg
rename to media/logo.svg
diff --git a/package.json b/package.json
index f6d23b1..2b5881e 100644
--- a/package.json
+++ b/package.json
@@ -1,19 +1,22 @@
{
"name": "chalk",
- "version": "1.0.0",
+ "version": "1.1.3",
"description": "Terminal string styling done right. Much color.",
"license": "MIT",
- "repository": "sindresorhus/chalk",
+ "repository": "chalk/chalk",
"maintainers": [
- "Sindre Sorhus <sindresorhus at gmail.com> (http://sindresorhus.com)",
- "Joshua Appelman <jappelman at xebia.com> (http://jbnicolai.com)"
+ "Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)",
+ "Joshua Appelman <jappelman at xebia.com> (jbnicolai.com)",
+ "JD Ballard <i.am.qix at gmail.com> (github.com/qix-)"
],
"engines": {
"node": ">=0.10.0"
},
"scripts": {
- "test": "mocha",
- "bench": "matcha benchmark.js"
+ "test": "xo && mocha",
+ "bench": "matcha benchmark.js",
+ "coverage": "nyc npm test && nyc report",
+ "coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"files": [
"index.js"
@@ -26,7 +29,9 @@
"console",
"cli",
"string",
+ "str",
"ansi",
+ "style",
"styles",
"tty",
"formatting",
@@ -40,14 +45,26 @@
"text"
],
"dependencies": {
- "ansi-styles": "^2.0.1",
+ "ansi-styles": "^2.2.1",
"escape-string-regexp": "^1.0.2",
- "has-ansi": "^1.0.3",
- "strip-ansi": "^2.0.1",
- "supports-color": "^1.3.0"
+ "has-ansi": "^2.0.0",
+ "strip-ansi": "^3.0.0",
+ "supports-color": "^2.0.0"
},
"devDependencies": {
+ "coveralls": "^2.11.2",
"matcha": "^0.6.0",
- "mocha": "*"
+ "mocha": "*",
+ "nyc": "^3.0.0",
+ "require-uncached": "^1.0.2",
+ "resolve-from": "^1.0.0",
+ "semver": "^4.3.3",
+ "xo": "*"
+ },
+ "xo": {
+ "envs": [
+ "node",
+ "mocha"
+ ]
}
}
diff --git a/readme.md b/readme.md
index 43c7064..5cf111e 100644
--- a/readme.md
+++ b/readme.md
@@ -1,19 +1,24 @@
<h1 align="center">
<br>
- <img width="360" src="https://cdn.rawgit.com/sindresorhus/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
+ <br>
+ <img width="360" src="https://cdn.rawgit.com/chalk/chalk/19935d6484811c5e468817f846b7b3d417d7bf4a/logo.svg" alt="chalk">
+ <br>
<br>
<br>
</h1>
> Terminal string styling done right
-[![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)
+[![Build Status](https://travis-ci.org/chalk/chalk.svg?branch=master)](https://travis-ci.org/chalk/chalk)
+[![Coverage Status](https://coveralls.io/repos/chalk/chalk/badge.svg?branch=master)](https://coveralls.io/r/chalk/chalk?branch=master)
+[![](http://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://www.youtube.com/watch?v=9auOCbH5Ns4)
+
[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.
**Chalk is a clean and focused alternative.**
-![screenshot](https://github.com/sindresorhus/ansi-styles/raw/master/screenshot.png)
+![](https://github.com/chalk/ansi-styles/raw/master/screenshot.png)
## Why
@@ -25,7 +30,7 @@
- Clean and focused
- Auto-detects color support
- Actively maintained
-- [Used by ~3000 modules](https://www.npmjs.com/browse/depended/chalk)
+- [Used by ~4500 modules](https://www.npmjs.com/browse/depended/chalk) as of July 15, 2015
## Install
@@ -104,13 +109,13 @@ var ctx = new chalk.constructor({enabled: false});
### chalk.supportsColor
-Detect whether the terminal [supports color](https://github.com/sindresorhus/supports-color). Used internally and handled for you, but exposed for convenience.
+Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
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`.
### chalk.styles
-Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-styles).
+Exposes the styles as [ANSI escape codes](https://github.com/chalk/ansi-styles).
Generally not useful, but you might need just the `.open` or `.close` escape code if you're mixing externally styled strings with your own.
@@ -125,11 +130,11 @@ console.log(chalk.styles.red.open + 'Hello' + chalk.styles.red.close);
### chalk.hasColor(string)
-Check whether a string [has color](https://github.com/sindresorhus/has-ansi).
+Check whether a string [has color](https://github.com/chalk/has-ansi).
### chalk.stripColor(string)
-[Strip color](https://github.com/sindresorhus/strip-ansi) from a string.
+[Strip color](https://github.com/chalk/strip-ansi) from a string.
Can be useful in combination with `.supportsColor` to strip color on externally styled text when it's not supported.
@@ -184,7 +189,7 @@ if (!chalk.supportsColor) {
## 256-colors
-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.
+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.
## Windows
@@ -192,6 +197,17 @@ Chalk does not support support anything other than the base eight colors, which
If you're on Windows, do yourself a favor and use [`cmder`](http://bliker.github.io/cmder/) instead of `cmd.exe`.
+## Related
+
+- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
+- [ansi-styles](https://github.com/chalk/ansi-styles/) - ANSI escape codes for styling strings in the terminal
+- [supports-color](https://github.com/chalk/supports-color/) - Detect whether a terminal supports color
+- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
+- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
+- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
+- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
+
+
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
diff --git a/test.js b/test.js
index 5787e18..1e6d75e 100644
--- a/test.js
+++ b/test.js
@@ -1,5 +1,8 @@
'use strict';
var assert = require('assert');
+var requireUncached = require('require-uncached');
+var resolveFrom = require('resolve-from');
+var semver = require('semver');
var chalk = require('./');
describe('chalk', function () {
@@ -32,7 +35,7 @@ describe('chalk', function () {
assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001b[0m\u001b[31m\u001b[42m\u001b[4mfoo\u001b[24m\u001b[49m\u001b[39mfoo\u001b[0m');
});
- it('should be able to cache multiple styles', function() {
+ it('should be able to cache multiple styles', function () {
var red = chalk.red;
var green = chalk.green;
var redBold = red.bold;
@@ -60,6 +63,64 @@ describe('chalk', function () {
});
});
+describe('chalk on windows', function () {
+ var originalEnv;
+ var originalPlatform;
+
+ // in node versions older than 0.12.x process.platform cannot be overridden
+ if (semver.lt(process.version, '0.12.0')) {
+ return;
+ }
+
+ before(function () {
+ originalEnv = process.env;
+ originalPlatform = process.platform;
+ });
+
+ after(function () {
+ process.env = originalEnv;
+ Object.defineProperty(process, 'platform', {value: originalPlatform});
+ });
+
+ beforeEach(function () {
+ process.env = {};
+ Object.defineProperty(process, 'platform', {value: 'win32'});
+ // since chalk internally modifies ansiStyles.blue.open, ansi-styles needs
+ // to be removed from the require cache for require-uncached to work
+ delete require.cache[resolveFrom(__dirname, 'ansi-styles')];
+ });
+
+ it('should replace blue foreground color in cmd.exe', function () {
+ process.env.TERM = 'dumb';
+ var chalkCtx = requireUncached('./');
+ assert.equal(chalkCtx.blue('foo'), '\u001b[94mfoo\u001b[39m');
+ });
+
+ it('shouldn\'t replace blue foreground color in xterm based terminals', function () {
+ process.env.TERM = 'xterm-256color';
+ var chalkCtx = requireUncached('./');
+ assert.equal(chalkCtx.blue('foo'), '\u001b[34mfoo\u001b[39m');
+ });
+
+ it('should not apply dimmed styling on gray strings, see https://github.com/chalk/chalk/issues/58', function () {
+ process.env.TERM = 'dumb';
+ var chalkCtx = requireUncached('./');
+ assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90mfoo\u001b[22m\u001b[39m');
+ });
+
+ it('should apply dimmed styling on xterm compatible terminals', function () {
+ process.env.TERM = 'xterm';
+ var chalkCtx = requireUncached('./');
+ assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90m\u001b[2mfoo\u001b[22m\u001b[39m');
+ });
+
+ it('should apply dimmed styling on strings of other colors', function () {
+ process.env.TERM = 'dumb';
+ var chalkCtx = requireUncached('./');
+ assert.equal(chalkCtx.blue.dim('foo'), '\u001b[94m\u001b[2mfoo\u001b[22m\u001b[39m');
+ });
+});
+
describe('chalk.enabled', function () {
it('should not output colors when manually disabled', function () {
chalk.enabled = false;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-chalk.git
More information about the Pkg-javascript-commits
mailing list