Merge branch 'master' into 256-truecolor

This commit is contained in:
Sindre Sorhus 2017-06-20 15:05:35 +02:00 committed by GitHub
commit 8c873a3732
7 changed files with 50 additions and 16 deletions

View file

@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
[{package.json,*.yml}] [*.yml]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2

1
.gitattributes vendored
View file

@ -1 +1,2 @@
* text=auto * text=auto
*.js text eol=lf

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const chalk = require('./'); const chalk = require('.');
// generates screenshot // Generates screenshot
for (const key of Object.keys(chalk.styles)) { for (const key of Object.keys(chalk.styles)) {
let ret = key; let ret = key;

View file

@ -79,8 +79,19 @@ function build(_styles, key) {
return applyStyle.apply(builder, arguments); return applyStyle.apply(builder, arguments);
}; };
var self = this;
builder._styles = _styles; builder._styles = _styles;
builder.level = this.level;
Object.defineProperty(builder, 'level', {
enumerable: true,
get: function () {
return self.level;
},
set: function (level) {
self.level = level;
}
});
// see below for fix regarding invisible grey/dim combination on windows. // see below for fix regarding invisible grey/dim combination on windows.
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey';

View file

@ -10,7 +10,7 @@
"JD Ballard <i.am.qix@gmail.com> (github.com/qix-)" "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
], ],
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=4"
}, },
"scripts": { "scripts": {
"test": "xo && nyc mocha", "test": "xo && nyc mocha",
@ -50,11 +50,11 @@
}, },
"devDependencies": { "devDependencies": {
"coveralls": "^2.11.2", "coveralls": "^2.11.2",
"import-fresh": "^2.0.0",
"matcha": "^0.7.0", "matcha": "^0.7.0",
"mocha": "*", "mocha": "*",
"nyc": "^6.1.1", "nyc": "^10.3.2",
"require-uncached": "^1.0.2", "resolve-from": "^3.0.0",
"resolve-from": "^2.0.0",
"semver": "^5.1.0", "semver": "^5.1.0",
"xo": "^0.16.0" "xo": "^0.16.0"
}, },

View file

@ -27,7 +27,7 @@
- Clean and focused - Clean and focused
- Auto-detects color support - Auto-detects color support
- Actively maintained - Actively maintained
- [Used by ~10,000 modules](https://www.npmjs.com/browse/depended/chalk) as of August 2nd, 2016 - [Used by ~16,000 modules](https://www.npmjs.com/browse/depended/chalk) as of May 31st, 2017
## Install ## Install

36
test.js
View file

@ -1,9 +1,9 @@
'use strict'; 'use strict';
var assert = require('assert'); var assert = require('assert');
var requireUncached = require('require-uncached'); var importFresh = require('import-fresh');
var resolveFrom = require('resolve-from'); var resolveFrom = require('resolve-from');
var semver = require('semver'); var semver = require('semver');
var chalk = require('./'); var chalk = require('.');
describe('chalk', function () { describe('chalk', function () {
it('should style string', function () { it('should style string', function () {
@ -123,31 +123,31 @@ describe('chalk on windows', function () {
it('should replace blue foreground color in cmd.exe', function () { it('should replace blue foreground color in cmd.exe', function () {
process.env.TERM = 'dumb'; process.env.TERM = 'dumb';
var chalkCtx = requireUncached('./'); var chalkCtx = importFresh('.');
assert.equal(chalkCtx.blue('foo'), '\u001b[94mfoo\u001b[39m'); assert.equal(chalkCtx.blue('foo'), '\u001b[94mfoo\u001b[39m');
}); });
it('shouldn\'t replace blue foreground color in xterm based terminals', function () { it('shouldn\'t replace blue foreground color in xterm based terminals', function () {
process.env.TERM = 'xterm-256color'; process.env.TERM = 'xterm-256color';
var chalkCtx = requireUncached('./'); var chalkCtx = importFresh('.');
assert.equal(chalkCtx.blue('foo'), '\u001b[34mfoo\u001b[39m'); 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 () { it('should not apply dimmed styling on gray strings, see https://github.com/chalk/chalk/issues/58', function () {
process.env.TERM = 'dumb'; process.env.TERM = 'dumb';
var chalkCtx = requireUncached('./'); var chalkCtx = importFresh('.');
assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90mfoo\u001b[22m\u001b[39m'); assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90mfoo\u001b[22m\u001b[39m');
}); });
it('should apply dimmed styling on xterm compatible terminals', function () { it('should apply dimmed styling on xterm compatible terminals', function () {
process.env.TERM = 'xterm'; process.env.TERM = 'xterm';
var chalkCtx = requireUncached('./'); var chalkCtx = importFresh('.');
assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90m\u001b[2mfoo\u001b[22m\u001b[39m'); 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 () { it('should apply dimmed styling on strings of other colors', function () {
process.env.TERM = 'dumb'; process.env.TERM = 'dumb';
var chalkCtx = requireUncached('./'); var chalkCtx = importFresh('.');
assert.equal(chalkCtx.blue.dim('foo'), '\u001b[94m\u001b[2mfoo\u001b[22m\u001b[39m'); assert.equal(chalkCtx.blue.dim('foo'), '\u001b[94m\u001b[2mfoo\u001b[22m\u001b[39m');
}); });
}); });
@ -159,6 +159,28 @@ describe('chalk.level', function () {
assert.equal(chalk.red('foo'), 'foo'); assert.equal(chalk.red('foo'), 'foo');
chalk.level = oldLevel; chalk.level = oldLevel;
}); });
it('should enable/disable colors based on overall chalk enabled property, not individual instances', function () {
chalk.enabled = true;
var red = chalk.red;
assert.equal(red.enabled, true);
chalk.enabled = false;
assert.equal(red.enabled, chalk.enabled);
chalk.enabled = true;
});
it('should propagate enable/disable changes from child colors', function () {
chalk.enabled = true;
var red = chalk.red;
assert.equal(red.enabled, true);
assert.equal(chalk.enabled, true);
red.enabled = false;
assert.equal(red.enabled, false);
assert.equal(chalk.enabled, false);
chalk.enabled = true;
assert.equal(red.enabled, true);
assert.equal(chalk.enabled, true);
});
}); });
describe('chalk.constructor', function () { describe('chalk.constructor', function () {