Adds support for nested chalk expressions.
green(a + blue(b) + c) will now look the same as green(a) + blue(b) + green(c), as expected. In the previous implementation the output would have been green(a) + blue(b) + c, because the reset code of the second expression would close all expressions around it as well. Now this reset code is replaced by a start code of the outer lying expression, both stopping the inner and re-starting the outer.
This commit is contained in:
parent
144421dc16
commit
d16b0ce367
3 changed files with 29 additions and 1 deletions
7
test.js
7
test.js
|
|
@ -21,6 +21,13 @@ describe('chalk', function () {
|
|||
);
|
||||
});
|
||||
|
||||
it('should support nesting styles of the same type (color, underline, bg)', function () {
|
||||
assert.equal(
|
||||
chalk.red('a' + chalk.blue('b' + chalk.green('c') + 'b') + 'c'),
|
||||
'\u001b[31ma\u001b[34mb\u001b[32mc\u001b[34mb\u001b[31mc\u001b[39m'
|
||||
);
|
||||
});
|
||||
|
||||
it('should reset all styles with `.reset()`', function () {
|
||||
assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue