diff --git a/index.d.ts b/index.d.ts index 74ff581..2d769a7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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. */ ansi256: (index: number) => this; - + /** Use RGB values to set background color. */ diff --git a/readme.md b/readme.md index 79dd4d0..ed9b312 100644 --- a/readme.md +++ b/readme.md @@ -274,7 +274,7 @@ 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. @@ -289,7 +289,7 @@ Examples: - `chalk.hex('#DEADED').underline('Hello, world!')` - `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.bgRgb(15, 100, 204).inverse('Hello!')` diff --git a/source/index.js b/source/index.js index 9f5f679..79bdabc 100644 --- a/source/index.js +++ b/source/index.js @@ -10,12 +10,12 @@ const {stdout: stdoutColor, stderr: stderrColor} = supportsColor; const {isArray} = Array; // `supportsColor.level` → `ansiStyles.color[name]` mapping -const levelMapping = new Set([ +const levelMapping = [ 'ansi256', 'ansi256', 'ansi256', 'ansi16m' -]); +]; const styles = Object.create(null); diff --git a/test/chalk.js b/test/chalk.js index adc1aed..035ad30 100644 --- a/test/chalk.js +++ b/test/chalk.js @@ -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'); }); -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 => { 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'); diff --git a/test/template-literal.js b/test/template-literal.js index 773e097..e8d5950 100644 --- a/test/template-literal.js +++ b/test/template-literal.js @@ -150,18 +150,18 @@ test('correctly parses unicode/hex escapes', t => { test('correctly parses string arguments', t => { 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`{keyword('blac\x6B').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('#000000').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`{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 => { const instance = new Chalk({level: 3}); // Keep level at least 1 in case we optimize for disabled chalk instances try { - console.log(instance`{keyword(????) hi}`); + console.log(instance`{hex(????) hi}`); t.fail(); } 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\')'); } });