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
|
|
@ -47,6 +47,9 @@ console.log( chalk.blue.bgRed.bold('Hello world!') );
|
|||
// nest styles
|
||||
console.log( chalk.red('Hello', chalk.underline.bgBlue('world') + '!') );
|
||||
|
||||
// nest styles of the same type even (colour, underline, background)
|
||||
console.log( chalk.green('Hello, I'm a green line ' + chalk.blue('with a blue substring') + ' that becomes green again!') );
|
||||
|
||||
// pass in multiple arguments
|
||||
console.log( chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz') );
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue