Fixes
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
83341478e9
commit
88f323fb16
5 changed files with 10 additions and 15 deletions
2
index.d.ts
vendored
2
index.d.ts
vendored
|
|
@ -187,7 +187,7 @@ export interface ChalkInstance extends ChalkFunction {
|
||||||
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
||||||
*/
|
*/
|
||||||
ansi256: (index: number) => this;
|
ansi256: (index: number) => this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use RGB values to set background color.
|
Use RGB values to set background color.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ console.log(chalk.bold.rgb(10, 100, 200)`Hello!`);
|
||||||
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
|
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain spaces between parameters.
|
Note that function styles (`rgb()`, `hsl()`, etc.) may not contain spaces between parameters.
|
||||||
|
|
||||||
All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
|
All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
|
||||||
|
|
||||||
|
|
@ -289,7 +289,7 @@ Examples:
|
||||||
- `chalk.hex('#DEADED').underline('Hello, world!')`
|
- `chalk.hex('#DEADED').underline('Hello, world!')`
|
||||||
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
|
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
|
||||||
|
|
||||||
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `keyword` for foreground colors and `bgKeyword` for background colors).
|
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `hex` for foreground colors and `bgHex` for background colors).
|
||||||
|
|
||||||
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
|
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
|
||||||
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
|
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
|
||||||
const {isArray} = Array;
|
const {isArray} = Array;
|
||||||
|
|
||||||
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
||||||
const levelMapping = new Set([
|
const levelMapping = [
|
||||||
'ansi256',
|
'ansi256',
|
||||||
'ansi256',
|
'ansi256',
|
||||||
'ansi256',
|
'ansi256',
|
||||||
'ansi16m'
|
'ansi16m'
|
||||||
]);
|
];
|
||||||
|
|
||||||
const styles = Object.create(null);
|
const styles = Object.create(null);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,11 +93,6 @@ test('line breaks should open and close colors with CRLF', t => {
|
||||||
t.is(chalk.grey('hello\r\nworld'), '\u001B[90mhello\u001B[39m\r\n\u001B[90mworld\u001B[39m');
|
t.is(chalk.grey('hello\r\nworld'), '\u001B[90mhello\u001B[39m\r\n\u001B[90mworld\u001B[39m');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('properly convert RGB to 16 colors on basic color terminals', t => {
|
|
||||||
t.is(new Chalk({level: 1}).hex('#FF0000')('hello'), '\u001B[91mhello\u001B[39m');
|
|
||||||
t.is(new Chalk({level: 1}).bgHex('#FF0000')('hello'), '\u001B[101mhello\u001B[49m');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('properly convert RGB to 256 colors on basic color terminals', t => {
|
test('properly convert RGB to 256 colors on basic color terminals', t => {
|
||||||
t.is(new Chalk({level: 2}).hex('#FF0000')('hello'), '\u001B[38;5;196mhello\u001B[39m');
|
t.is(new Chalk({level: 2}).hex('#FF0000')('hello'), '\u001B[38;5;196mhello\u001B[39m');
|
||||||
t.is(new Chalk({level: 2}).bgHex('#FF0000')('hello'), '\u001B[48;5;196mhello\u001B[49m');
|
t.is(new Chalk({level: 2}).bgHex('#FF0000')('hello'), '\u001B[48;5;196mhello\u001B[49m');
|
||||||
|
|
|
||||||
|
|
@ -150,18 +150,18 @@ test('correctly parses unicode/hex escapes', t => {
|
||||||
|
|
||||||
test('correctly parses string arguments', t => {
|
test('correctly parses string arguments', t => {
|
||||||
const instance = new Chalk({level: 3});
|
const instance = new Chalk({level: 3});
|
||||||
t.is(instance`{keyword('black').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
t.is(instance`{hex('#000000').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
||||||
t.is(instance`{keyword('blac\x6B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
t.is(instance`{hex('#00000\x30').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
||||||
t.is(instance`{keyword('blac\u006B').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
t.is(instance`{hex('#00000\u0030').bold can haz cheezburger}`, '\u001B[38;2;0;0;0m\u001B[1mcan haz cheezburger\u001B[22m\u001B[39m');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws if a bad argument is encountered', t => {
|
test('throws if a bad argument is encountered', t => {
|
||||||
const instance = new Chalk({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances
|
const instance = new Chalk({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances
|
||||||
try {
|
try {
|
||||||
console.log(instance`{keyword(????) hi}`);
|
console.log(instance`{hex(????) hi}`);
|
||||||
t.fail();
|
t.fail();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
t.is(error.message, 'Invalid Chalk template style argument: ???? (in style \'keyword\')');
|
t.is(error.message, 'Invalid Chalk template style argument: ???? (in style \'hex\')');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue