diff --git a/index.d.ts b/index.d.ts index c50c17e..7e22c45 100644 --- a/index.d.ts +++ b/index.d.ts @@ -213,6 +213,14 @@ declare namespace chalk { */ hwb(hue: number, whiteness: number, blackness: number): Chalk; + /** + Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color. + + 30 <= code && code < 38 || 90 <= code && code < 98 + For example, 31 for red, 91 for redBright. + */ + ansi(code: number): Chalk; + /** Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color. */ @@ -266,6 +274,15 @@ declare namespace chalk { */ bgHwb(hue: number, whiteness: number, blackness: number): Chalk; + /** + Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color. + + 30 <= code && code < 38 || 90 <= code && code < 98 + For example, 31 for red, 91 for redBright. + Use the foreground code, not the background code (for example, not 41, nor 101). + */ + bgAnsi(code: number): Chalk; + /** Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color. */ diff --git a/index.test-d.ts b/index.test-d.ts index dd3ba99..177d6de 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -49,6 +49,7 @@ expectType(chalk.rgb(0, 0, 0)); expectType(chalk.hsl(0, 0, 0)); expectType(chalk.hsv(0, 0, 0)); expectType(chalk.hwb(0, 0, 0)); +expectType(chalk.ansi(30)); expectType(chalk.ansi256(0)); expectType(chalk.bgHex('#DEADED')); expectType(chalk.bgKeyword('orange')); @@ -56,6 +57,7 @@ expectType(chalk.bgRgb(0, 0, 0)); expectType(chalk.bgHsl(0, 0, 0)); expectType(chalk.bgHsv(0, 0, 0)); expectType(chalk.bgHwb(0, 0, 0)); +expectType(chalk.bgAnsi(30)); expectType(chalk.bgAnsi256(0)); // -- Modifiers -- diff --git a/readme.md b/readme.md index aa0070a..54c4aff 100644 --- a/readme.md +++ b/readme.md @@ -261,7 +261,7 @@ The following color models can be used: - [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')` - [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')` - [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')` -- `ansi16` +- [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')` - [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`