Fixing some of requested changes for pull request
This commit is contained in:
parent
4c26f9128d
commit
eb2565ce3d
6 changed files with 63 additions and 23 deletions
31
readme.md
31
readme.md
|
|
@ -165,19 +165,36 @@ The wrapper marks the unprintable characters from style tags.
|
|||
A wrapper can be added to the styles, so you can escape characters or add marks to then.
|
||||
By default, these wrappers are empty strings `""`.
|
||||
|
||||
The wrappers object has two properties, `pre` and `post`.
|
||||
The wrappers object has two properties, `before` and `after`.
|
||||
For example:
|
||||
|
||||
```js
|
||||
const ctx = new chalk.constructor({wrapper: {
|
||||
pre: '>',
|
||||
post: '<',
|
||||
}});
|
||||
const ctx = new chalk.constructor({
|
||||
wrapper: {
|
||||
before: '>',
|
||||
after: '<'
|
||||
}
|
||||
});
|
||||
|
||||
ctx.red('foo') // outputs "><foo><"
|
||||
ctx.red('foo') // outputs ">\u001B[31m<foo>\u001B[39m<"
|
||||
```
|
||||
|
||||
This can be specially useful when escaping characters, using it into a _PS1_ string or debugging and outputing it into different terminals/TTYs.
|
||||
This can be specially useful when escaping characters, using it into a _PS1_ string or debugging and outputing it into different terminals/TTYs.
|
||||
That's because _PS1_ uses the number of _printable_ characters to know the length of the string and to position the cursor. If you don't mark the colour codes as "unprintable" by using `\[` and `\]`, those characteres will be used to determine the length of the string, mispositioning the cursor.
|
||||
|
||||
```js
|
||||
const ctx = new chalk.constructor({
|
||||
wrapper: {
|
||||
before: '\\[',
|
||||
after: '\\]'
|
||||
}
|
||||
});
|
||||
|
||||
ctx.red('foo') // outputs "\\[\u001B[31m\\]foo\\[\u001B[39m\\]" (marking the colour codes as unpritable)
|
||||
```
|
||||
|
||||
That would output "foo" in red, as that is the printable result.
|
||||
|
||||
|
||||
### chalk.supportsColor
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue