Adds 256 color support.
This commit is contained in:
parent
03b92b1bb8
commit
79c6bdcfd8
3 changed files with 21 additions and 0 deletions
9
index.js
9
index.js
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
var escapeStringRegexp = require('escape-string-regexp');
|
var escapeStringRegexp = require('escape-string-regexp');
|
||||||
|
var ansi8bit = require('ansi-8-bit');
|
||||||
var ansiStyles = require('ansi-styles');
|
var ansiStyles = require('ansi-styles');
|
||||||
var stripAnsi = require('strip-ansi');
|
var stripAnsi = require('strip-ansi');
|
||||||
var hasAnsi = require('has-ansi');
|
var hasAnsi = require('has-ansi');
|
||||||
|
|
@ -84,6 +85,14 @@ function init() {
|
||||||
|
|
||||||
defineProps(chalk, init());
|
defineProps(chalk, init());
|
||||||
|
|
||||||
|
chalk.foreground = function (r, g, b, str) {
|
||||||
|
return ansi8bit.fg.getRgb(r, g, b) + str + ansi8bit.reset;
|
||||||
|
};
|
||||||
|
|
||||||
|
chalk.background = function (r, g, b, str) {
|
||||||
|
return ansi8bit.bg.getRgb(r, g, b) + str + ansi8bit.reset;
|
||||||
|
};
|
||||||
|
|
||||||
chalk.styles = ansiStyles;
|
chalk.styles = ansiStyles;
|
||||||
chalk.hasColor = hasAnsi;
|
chalk.hasColor = hasAnsi;
|
||||||
chalk.stripColor = stripAnsi;
|
chalk.stripColor = stripAnsi;
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
"text"
|
"text"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"ansi-8-bit": "^1.0.1",
|
||||||
"ansi-styles": "^1.1.0",
|
"ansi-styles": "^1.1.0",
|
||||||
"escape-string-regexp": "^1.0.1",
|
"escape-string-regexp": "^1.0.1",
|
||||||
"has-ansi": "^0.1.0",
|
"has-ansi": "^0.1.0",
|
||||||
|
|
|
||||||
11
test.js
11
test.js
|
|
@ -86,3 +86,14 @@ describe('chalk.stripColor()', function () {
|
||||||
assert.equal(chalk.stripColor(chalk.underline.red.bgGreen('foo')), 'foo');
|
assert.equal(chalk.stripColor(chalk.underline.red.bgGreen('foo')), 'foo');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('chalk.foreground() and chalk.background()', function () {
|
||||||
|
it('should style according to their given rgb values', function () {
|
||||||
|
assert.equal(chalk.foreground(2, 5, 3, 'foobar'), '\u001b[;38;5;121mfoobar\u001b[0m');
|
||||||
|
});
|
||||||
|
it('should play nice with other chalk styles', function () {
|
||||||
|
assert.equal(chalk.background(1, 3, 3, chalk.red("Unicorns, attack!")), '\u001b[;48;5;73m\u001b[31mUnicorns, attack!\u001b[39m\u001b[0m');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue