From f5d282b07a8db2d52c3ab3726087e32fb410b5d7 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 3 Aug 2013 03:38:42 +0200 Subject: [PATCH 001/346] 0.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e0cd865..ff0de7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chalk", - "version": "0.1.0", + "version": "0.1.1", "description": "Terminal string styling done right", "keywords": [ "color", From d60eeb9df373f5a85bb024d4df21a1ec40601c66 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 3 Aug 2013 03:38:42 +0200 Subject: [PATCH 002/346] 0.1.1 --- package.json | 2 +- readme.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e0cd865..ff0de7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chalk", - "version": "0.1.0", + "version": "0.1.1", "description": "Terminal string styling done right", "keywords": [ "color", diff --git a/readme.md b/readme.md index 35c61d0..1941ad8 100644 --- a/readme.md +++ b/readme.md @@ -50,7 +50,7 @@ console.log(error('Error!')); ## API -### chalk.\\[.\...\](*string*) +### chalk.\\[.\...\](string) Chain [styles](#styles) and call the last one as a method with a string argument. @@ -77,7 +77,7 @@ console.log(chalk.styles.red); //=> \x1b[31m ``` -### chalk.stripColor(*string*) +### chalk.stripColor(string) Strip color from a string. From c323bf0cafbae42dc403c70b3f26b4b7d85c7024 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 3 Aug 2013 18:47:47 +0200 Subject: [PATCH 003/346] Add support for nested styles --- chalk.js | 14 +++++--------- package.json | 2 +- readme.md | 15 ++++++++++----- test.js | 23 +++++++++++++++++------ 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/chalk.js b/chalk.js index d4887e1..bdb0ef5 100644 --- a/chalk.js +++ b/chalk.js @@ -6,11 +6,9 @@ var styles = (function () { var ret = {}; Object.keys(ansi).forEach(function (key) { - var code = ansi[key]; ret[key] = { - enumerable: true, get: function () { - this._styles.push(code); + this._styles.push(key); return this; } }; @@ -25,19 +23,17 @@ function init() { var ret = {}; Object.keys(styles).forEach(function (name) { - var code = styles[name]; - ret[name] = { - enumerable: true, get: function () { var obj = defineProps(function self(str) { if (!chalk.enabled) { return str; } - return self._styles.reduce(function (str, code) { - return code + (str || ''); - }, str) + ansi['reset']; + return self._styles.reduce(function (str, name) { + var code = ansi[name]; + return code[0] + (str || '') + code[1]; + }, str); }, styles); obj._styles = []; diff --git a/package.json b/package.json index ff0de7d..1e9e5c1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "has-color": "~0.1.0", - "ansi-styles": "~0.1.0" + "ansi-styles": "~0.2.0" }, "devDependencies": { "mocha": "~1.12.0" diff --git a/readme.md b/readme.md index 1941ad8..90158a7 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ > Terminal string styling done right. -[colors.js](https://github.com/Marak/colors.js) is currently the most popular coloring module, but it has serious deficiencies like extending String.prototype which causes all kinds of problems. Although there are other ones, they either do too much or not enough. +[colors.js](https://github.com/Marak/colors.js) is currently the most popular string styling module, but it has serious deficiencies like extending String.prototype which causes all kinds of problems. Although there are other ones, they either do too much or not enough. **Chalk is a clean and focused alternative.** @@ -13,6 +13,7 @@ - **Doesn't extend String.prototype** - Expressive API +- Clean and focused - Auto-detects color support - Actively maintained @@ -37,6 +38,9 @@ console.log(chalk.blue('Hello') + 'World' + chalk.red('!')); // compose multiple styles using the chainable API console.log(chalk.blue.bgRed.bold('Hello world!')); + +// nest styles +chalk.red('Hello' + chalk.underline.bgBlue('world') + '!'); ``` You can easily define your own themes. @@ -73,8 +77,12 @@ Exposes the styles as [ANSI escape codes](https://github.com/sindresorhus/ansi-s ```js var chalk = require('chalk'); + console.log(chalk.styles.red); -//=> \x1b[31m +//=> ['\x1b[31m', '\x1b[39m'] + +console.log(chalk.styles.red[0] + 'Hello' + chalk.styles.red[1]); +// first item is the style escape code and second is the reset escape code ``` ### chalk.stripColor(string) @@ -90,7 +98,6 @@ Strip color from a string. - bold - italic - underline -- blink - inverse - strikethrough @@ -104,7 +111,6 @@ Strip color from a string. - magenta - cyan - white -- default - gray ### Background colors @@ -117,7 +123,6 @@ Strip color from a string. - bgMagenta - bgCyan - bgWhite -- bgDefault ## License diff --git a/test.js b/test.js index ba37141..3d95dcb 100644 --- a/test.js +++ b/test.js @@ -5,14 +5,25 @@ var chalk = require('./chalk'); describe('chalk', function () { it('should style string', function () { - assert.equal(chalk.underline('foo'), '\x1b[4mfoo\x1b[0m'); - assert.equal(chalk.red('foo'), '\x1b[31mfoo\x1b[0m'); - assert.equal(chalk.bgRed('foo'), '\x1b[41mfoo\x1b[0m'); + assert.equal(chalk.underline('foo'), '\x1b[4mfoo\x1b[24m'); + assert.equal(chalk.red('foo'), '\x1b[31mfoo\x1b[39m'); + assert.equal(chalk.bgRed('foo'), '\x1b[41mfoo\x1b[49m'); }); it('should support applying multiple styles at once', function () { - assert.equal(chalk.red.bgGreen.underline('foo'), '\x1b[4m\x1b[42m\x1b[31mfoo\x1b[0m'); - assert.equal(chalk.underline.red.bgGreen('foo'), '\x1b[42m\x1b[31m\x1b[4mfoo\x1b[0m'); + assert.equal(chalk.red.bgGreen.underline('foo'), '\x1b[4m\x1b[42m\x1b[31mfoo\x1b[39m\x1b[49m\x1b[24m'); + assert.equal(chalk.underline.red.bgGreen('foo'), '\x1b[42m\x1b[31m\x1b[4mfoo\x1b[24m\x1b[39m\x1b[49m'); + }); + + it('should support nesting styles', function () { + assert.equal( + chalk.red('foo' + chalk.underline.bgBlue('bar') + '!'), + '\x1b[31mfoo\x1b[44m\x1b[4mbar\x1b[24m\x1b[49m!\x1b[39m' + ); + }); + + it('should reset all styles with `.reset()`', function () { + assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\x1b[0m\x1b[4m\x1b[42m\x1b[31mfoo\x1b[39m\x1b[49m\x1b[24mfoo\x1b[0m'); }); }); @@ -26,7 +37,7 @@ describe('chalk.enabled', function () { describe('chalk.styles', function () { it('should expose the styles as ANSI escape codes', function () { - assert.equal(chalk.styles.red, '\x1b[31m'); + assert.equal(chalk.styles.red[0], '\x1b[31m'); }); }); From c8f8a1f6f3f1d146a617a6f0e1e044405ba56835 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 3 Aug 2013 18:48:02 +0200 Subject: [PATCH 004/346] 0.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e9e5c1..e1a4e1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chalk", - "version": "0.1.1", + "version": "0.2.0", "description": "Terminal string styling done right", "keywords": [ "color", From cbc3900ececcee1079cbbba8d3677c6c9310344b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 4 Aug 2013 22:04:43 +0200 Subject: [PATCH 005/346] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 90158a7..d369d2e 100644 --- a/readme.md +++ b/readme.md @@ -54,7 +54,7 @@ console.log(error('Error!')); ## API -### chalk.\\[.\...\](string) +### chalk.\