chalk 5.0.1 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -3
- package/readme.md +34 -14
- package/source/index.d.ts +71 -69
- package/source/index.js +13 -0
- package/source/utilities.js +2 -2
- package/source/vendor/ansi-styles/index.d.ts +46 -0
- package/source/vendor/ansi-styles/index.js +69 -65
- package/source/vendor/supports-color/browser.js +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chalk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Terminal string styling done right",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "chalk/chalk",
|
|
@@ -58,12 +58,15 @@
|
|
|
58
58
|
"log-update": "^5.0.0",
|
|
59
59
|
"matcha": "^0.7.0",
|
|
60
60
|
"tsd": "^0.19.0",
|
|
61
|
-
"xo": "^0.
|
|
61
|
+
"xo": "^0.52.4",
|
|
62
62
|
"yoctodelay": "^2.0.0"
|
|
63
63
|
},
|
|
64
64
|
"xo": {
|
|
65
65
|
"rules": {
|
|
66
|
-
"unicorn/prefer-string-slice": "off"
|
|
66
|
+
"unicorn/prefer-string-slice": "off",
|
|
67
|
+
"@typescript-eslint/consistent-type-imports": "off",
|
|
68
|
+
"@typescript-eslint/consistent-type-exports": "off",
|
|
69
|
+
"@typescript-eslint/consistent-type-definitions": "off"
|
|
67
70
|
}
|
|
68
71
|
},
|
|
69
72
|
"c8": {
|
package/readme.md
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
> Terminal string styling done right
|
|
11
11
|
|
|
12
12
|
[](https://codecov.io/gh/chalk/chalk)
|
|
13
|
-
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
|
|
14
|
-
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
|
|
14
|
+
[](https://www.npmjs.com/package/chalk)
|
|
15
|
+
[](https://repl.it/github/chalk/chalk)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+

|
|
18
18
|
|
|
19
19
|
<br>
|
|
20
20
|
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
<p>
|
|
25
25
|
<p>
|
|
26
26
|
<sup>
|
|
27
|
-
Sindre Sorhus' open source work is supported by the community on <a href="https://github.com/sponsors/sindresorhus">GitHub Sponsors</a>
|
|
27
|
+
Sindre Sorhus' open source work is supported by the community on <a href="https://github.com/sponsors/sindresorhus">GitHub Sponsors</a>
|
|
28
28
|
</sup>
|
|
29
29
|
</p>
|
|
30
30
|
<sup>Special thanks to:</sup>
|
|
31
31
|
<br>
|
|
32
32
|
<br>
|
|
33
33
|
<a href="https://standardresume.co/tech">
|
|
34
|
-
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="160"
|
|
34
|
+
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="160">
|
|
35
35
|
</a>
|
|
36
36
|
<br>
|
|
37
37
|
<br>
|
|
38
38
|
<a href="https://retool.com/?utm_campaign=sindresorhus">
|
|
39
|
-
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="230"
|
|
39
|
+
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="230">
|
|
40
40
|
</a>
|
|
41
41
|
<br>
|
|
42
42
|
<br>
|
|
@@ -61,6 +61,16 @@
|
|
|
61
61
|
<sup>It’s 100% JavaScript, fully customizable, and developer-first.</sup>
|
|
62
62
|
</div>
|
|
63
63
|
</a>
|
|
64
|
+
<br>
|
|
65
|
+
<br>
|
|
66
|
+
<a href="https://www.stackaid.us/?utm_campaign=sindre">
|
|
67
|
+
<div>
|
|
68
|
+
<img src="https://sindresorhus.com/assets/thanks/stackaid-logo.png" width="230" alt="StackAid">
|
|
69
|
+
</div>
|
|
70
|
+
<b>Fund your open source dependencies</b>
|
|
71
|
+
</a>
|
|
72
|
+
<br>
|
|
73
|
+
<br>
|
|
64
74
|
</p>
|
|
65
75
|
</div>
|
|
66
76
|
|
|
@@ -79,7 +89,7 @@
|
|
|
79
89
|
- Doesn't extend `String.prototype`
|
|
80
90
|
- Clean and focused
|
|
81
91
|
- Actively maintained
|
|
82
|
-
- [Used by ~
|
|
92
|
+
- [Used by ~86,000 packages](https://www.npmjs.com/browse/depended/chalk) as of October 4, 2022
|
|
83
93
|
|
|
84
94
|
## Install
|
|
85
95
|
|
|
@@ -200,6 +210,22 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
|
|
|
200
210
|
|
|
201
211
|
`chalkStderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `supportsColor` apply to this too. `supportsColorStderr` is exposed for convenience.
|
|
202
212
|
|
|
213
|
+
### modifierNames, foregroundColorNames, backgroundColorNames, and colorNames
|
|
214
|
+
|
|
215
|
+
All supported style strings are exposed as an array of strings for convenience. `colorNames` is the combination of `foregroundColorNames` and `backgroundColorNames`.
|
|
216
|
+
|
|
217
|
+
This can be useful if you wrap Chalk and need to validate input:
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
import {modifierNames, foregroundColorNames} from 'chalk';
|
|
221
|
+
|
|
222
|
+
console.log(modifierNames.includes('bold'));
|
|
223
|
+
//=> true
|
|
224
|
+
|
|
225
|
+
console.log(foregroundColorNames.includes('pink'));
|
|
226
|
+
//=> false
|
|
227
|
+
```
|
|
228
|
+
|
|
203
229
|
## Styles
|
|
204
230
|
|
|
205
231
|
### Modifiers
|
|
@@ -287,12 +313,6 @@ If you're on Windows, do yourself a favor and use [Windows Terminal](https://git
|
|
|
287
313
|
|
|
288
314
|
[colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68) and the package is unmaintained. Although there are other packages, they either do too much or not enough. Chalk is a clean and focused alternative.
|
|
289
315
|
|
|
290
|
-
## chalk for enterprise
|
|
291
|
-
|
|
292
|
-
Available as part of the Tidelift Subscription.
|
|
293
|
-
|
|
294
|
-
The maintainers of chalk and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-chalk?utm_source=npm-chalk&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
|
295
|
-
|
|
296
316
|
## Related
|
|
297
317
|
|
|
298
318
|
- [chalk-template](https://github.com/chalk/chalk-template) - [Tagged template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) support for this module
|
package/source/index.d.ts
CHANGED
|
@@ -1,76 +1,9 @@
|
|
|
1
1
|
// TODO: Make it this when TS suports that.
|
|
2
|
+
// import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles';
|
|
2
3
|
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
|
|
4
|
+
import {ModifierName, ForegroundColorName, BackgroundColorName, ColorName} from './vendor/ansi-styles/index.js';
|
|
3
5
|
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
|
|
4
6
|
|
|
5
|
-
/**
|
|
6
|
-
Basic foreground colors.
|
|
7
|
-
|
|
8
|
-
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
9
|
-
*/
|
|
10
|
-
export type ForegroundColor =
|
|
11
|
-
| 'black'
|
|
12
|
-
| 'red'
|
|
13
|
-
| 'green'
|
|
14
|
-
| 'yellow'
|
|
15
|
-
| 'blue'
|
|
16
|
-
| 'magenta'
|
|
17
|
-
| 'cyan'
|
|
18
|
-
| 'white'
|
|
19
|
-
| 'gray'
|
|
20
|
-
| 'grey'
|
|
21
|
-
| 'blackBright'
|
|
22
|
-
| 'redBright'
|
|
23
|
-
| 'greenBright'
|
|
24
|
-
| 'yellowBright'
|
|
25
|
-
| 'blueBright'
|
|
26
|
-
| 'magentaBright'
|
|
27
|
-
| 'cyanBright'
|
|
28
|
-
| 'whiteBright';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
Basic background colors.
|
|
32
|
-
|
|
33
|
-
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
34
|
-
*/
|
|
35
|
-
export type BackgroundColor =
|
|
36
|
-
| 'bgBlack'
|
|
37
|
-
| 'bgRed'
|
|
38
|
-
| 'bgGreen'
|
|
39
|
-
| 'bgYellow'
|
|
40
|
-
| 'bgBlue'
|
|
41
|
-
| 'bgMagenta'
|
|
42
|
-
| 'bgCyan'
|
|
43
|
-
| 'bgWhite'
|
|
44
|
-
| 'bgGray'
|
|
45
|
-
| 'bgGrey'
|
|
46
|
-
| 'bgBlackBright'
|
|
47
|
-
| 'bgRedBright'
|
|
48
|
-
| 'bgGreenBright'
|
|
49
|
-
| 'bgYellowBright'
|
|
50
|
-
| 'bgBlueBright'
|
|
51
|
-
| 'bgMagentaBright'
|
|
52
|
-
| 'bgCyanBright'
|
|
53
|
-
| 'bgWhiteBright';
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
Basic colors.
|
|
57
|
-
|
|
58
|
-
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
59
|
-
*/
|
|
60
|
-
export type Color = ForegroundColor | BackgroundColor;
|
|
61
|
-
|
|
62
|
-
export type Modifiers =
|
|
63
|
-
| 'reset'
|
|
64
|
-
| 'bold'
|
|
65
|
-
| 'dim'
|
|
66
|
-
| 'italic'
|
|
67
|
-
| 'underline'
|
|
68
|
-
| 'overline'
|
|
69
|
-
| 'inverse'
|
|
70
|
-
| 'hidden'
|
|
71
|
-
| 'strikethrough'
|
|
72
|
-
| 'visible';
|
|
73
|
-
|
|
74
7
|
export interface Options {
|
|
75
8
|
/**
|
|
76
9
|
Specify the color support for Chalk.
|
|
@@ -308,6 +241,12 @@ export const supportsColor: ColorInfo;
|
|
|
308
241
|
export const chalkStderr: typeof chalk;
|
|
309
242
|
export const supportsColorStderr: typeof supportsColor;
|
|
310
243
|
|
|
244
|
+
export {
|
|
245
|
+
ModifierName, ForegroundColorName, BackgroundColorName, ColorName,
|
|
246
|
+
modifierNames, foregroundColorNames, backgroundColorNames, colorNames,
|
|
247
|
+
// } from '#ansi-styles';
|
|
248
|
+
} from './vendor/ansi-styles/index.js';
|
|
249
|
+
|
|
311
250
|
export {
|
|
312
251
|
ColorInfo,
|
|
313
252
|
ColorSupport,
|
|
@@ -315,4 +254,67 @@ export {
|
|
|
315
254
|
// } from '#supports-color';
|
|
316
255
|
} from './vendor/supports-color/index.js';
|
|
317
256
|
|
|
257
|
+
// TODO: Remove these aliases in the next major version
|
|
258
|
+
/**
|
|
259
|
+
@deprecated Use `ModifierName` instead.
|
|
260
|
+
|
|
261
|
+
Basic modifier names.
|
|
262
|
+
*/
|
|
263
|
+
export type Modifiers = ModifierName;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
@deprecated Use `ForegroundColorName` instead.
|
|
267
|
+
|
|
268
|
+
Basic foreground color names.
|
|
269
|
+
|
|
270
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
271
|
+
*/
|
|
272
|
+
export type ForegroundColor = ForegroundColorName;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
@deprecated Use `BackgroundColorName` instead.
|
|
276
|
+
|
|
277
|
+
Basic background color names.
|
|
278
|
+
|
|
279
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
280
|
+
*/
|
|
281
|
+
export type BackgroundColor = BackgroundColorName;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
@deprecated Use `ColorName` instead.
|
|
285
|
+
|
|
286
|
+
Basic color names. The combination of foreground and background color names.
|
|
287
|
+
|
|
288
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
289
|
+
*/
|
|
290
|
+
export type Color = ColorName;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
@deprecated Use `modifierNames` instead.
|
|
294
|
+
|
|
295
|
+
Basic modifier names.
|
|
296
|
+
*/
|
|
297
|
+
export const modifiers: readonly Modifiers[];
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
@deprecated Use `foregroundColorNames` instead.
|
|
301
|
+
|
|
302
|
+
Basic foreground color names.
|
|
303
|
+
*/
|
|
304
|
+
export const foregroundColors: readonly ForegroundColor[];
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
@deprecated Use `backgroundColorNames` instead.
|
|
308
|
+
|
|
309
|
+
Basic background color names.
|
|
310
|
+
*/
|
|
311
|
+
export const backgroundColors: readonly BackgroundColor[];
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
@deprecated Use `colorNames` instead.
|
|
315
|
+
|
|
316
|
+
Basic color names. The combination of foreground and background color names.
|
|
317
|
+
*/
|
|
318
|
+
export const colors: readonly Color[];
|
|
319
|
+
|
|
318
320
|
export default chalk;
|
package/source/index.js
CHANGED
|
@@ -204,6 +204,19 @@ Object.defineProperties(createChalk.prototype, styles);
|
|
|
204
204
|
const chalk = createChalk();
|
|
205
205
|
export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
|
|
206
206
|
|
|
207
|
+
export {
|
|
208
|
+
modifierNames,
|
|
209
|
+
foregroundColorNames,
|
|
210
|
+
backgroundColorNames,
|
|
211
|
+
colorNames,
|
|
212
|
+
|
|
213
|
+
// TODO: Remove these aliases in the next major version
|
|
214
|
+
modifierNames as modifiers,
|
|
215
|
+
foregroundColorNames as foregroundColors,
|
|
216
|
+
backgroundColorNames as backgroundColors,
|
|
217
|
+
colorNames as colors,
|
|
218
|
+
} from './vendor/ansi-styles/index.js';
|
|
219
|
+
|
|
207
220
|
export {
|
|
208
221
|
stdoutColor as supportsColor,
|
|
209
222
|
stderrColor as supportsColorStderr,
|
package/source/utilities.js
CHANGED
|
@@ -9,7 +9,7 @@ export function stringReplaceAll(string, substring, replacer) {
|
|
|
9
9
|
let endIndex = 0;
|
|
10
10
|
let returnValue = '';
|
|
11
11
|
do {
|
|
12
|
-
returnValue += string.
|
|
12
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
13
13
|
endIndex = index + substringLength;
|
|
14
14
|
index = string.indexOf(substring, endIndex);
|
|
15
15
|
} while (index !== -1);
|
|
@@ -23,7 +23,7 @@ export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
|
23
23
|
let returnValue = '';
|
|
24
24
|
do {
|
|
25
25
|
const gotCR = string[index - 1] === '\r';
|
|
26
|
-
returnValue += string.
|
|
26
|
+
returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
|
27
27
|
endIndex = index + 1;
|
|
28
28
|
index = string.indexOf('\n', endIndex);
|
|
29
29
|
} while (index !== -1);
|
|
@@ -180,6 +180,52 @@ export interface ConvertColor {
|
|
|
180
180
|
hexToAnsi(hex: string): number;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
Basic modifier names.
|
|
185
|
+
*/
|
|
186
|
+
export type ModifierName = keyof Modifier;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
Basic foreground color names.
|
|
190
|
+
|
|
191
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
192
|
+
*/
|
|
193
|
+
export type ForegroundColorName = keyof ForegroundColor;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
Basic background color names.
|
|
197
|
+
|
|
198
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
199
|
+
*/
|
|
200
|
+
export type BackgroundColorName = keyof BackgroundColor;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
Basic color names. The combination of foreground and background color names.
|
|
204
|
+
|
|
205
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
206
|
+
*/
|
|
207
|
+
export type ColorName = ForegroundColorName | BackgroundColorName;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
Basic modifier names.
|
|
211
|
+
*/
|
|
212
|
+
export const modifierNames: readonly ModifierName[];
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
Basic foreground color names.
|
|
216
|
+
*/
|
|
217
|
+
export const foregroundColorNames: readonly ForegroundColorName[];
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
Basic background color names.
|
|
221
|
+
*/
|
|
222
|
+
export const backgroundColorNames: readonly BackgroundColorName[];
|
|
223
|
+
|
|
224
|
+
/*
|
|
225
|
+
Basic color names. The combination of foreground and background color names.
|
|
226
|
+
*/
|
|
227
|
+
export const colorNames: readonly ColorName[];
|
|
228
|
+
|
|
183
229
|
declare const ansiStyles: {
|
|
184
230
|
readonly modifier: Modifier;
|
|
185
231
|
readonly color: ColorBase & ForegroundColor;
|
|
@@ -6,68 +6,67 @@ const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
|
|
|
6
6
|
|
|
7
7
|
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
8
8
|
|
|
9
|
+
const styles = {
|
|
10
|
+
modifier: {
|
|
11
|
+
reset: [0, 0],
|
|
12
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
13
|
+
bold: [1, 22],
|
|
14
|
+
dim: [2, 22],
|
|
15
|
+
italic: [3, 23],
|
|
16
|
+
underline: [4, 24],
|
|
17
|
+
overline: [53, 55],
|
|
18
|
+
inverse: [7, 27],
|
|
19
|
+
hidden: [8, 28],
|
|
20
|
+
strikethrough: [9, 29],
|
|
21
|
+
},
|
|
22
|
+
color: {
|
|
23
|
+
black: [30, 39],
|
|
24
|
+
red: [31, 39],
|
|
25
|
+
green: [32, 39],
|
|
26
|
+
yellow: [33, 39],
|
|
27
|
+
blue: [34, 39],
|
|
28
|
+
magenta: [35, 39],
|
|
29
|
+
cyan: [36, 39],
|
|
30
|
+
white: [37, 39],
|
|
31
|
+
|
|
32
|
+
// Bright color
|
|
33
|
+
blackBright: [90, 39],
|
|
34
|
+
gray: [90, 39], // Alias of `blackBright`
|
|
35
|
+
grey: [90, 39], // Alias of `blackBright`
|
|
36
|
+
redBright: [91, 39],
|
|
37
|
+
greenBright: [92, 39],
|
|
38
|
+
yellowBright: [93, 39],
|
|
39
|
+
blueBright: [94, 39],
|
|
40
|
+
magentaBright: [95, 39],
|
|
41
|
+
cyanBright: [96, 39],
|
|
42
|
+
whiteBright: [97, 39],
|
|
43
|
+
},
|
|
44
|
+
bgColor: {
|
|
45
|
+
bgBlack: [40, 49],
|
|
46
|
+
bgRed: [41, 49],
|
|
47
|
+
bgGreen: [42, 49],
|
|
48
|
+
bgYellow: [43, 49],
|
|
49
|
+
bgBlue: [44, 49],
|
|
50
|
+
bgMagenta: [45, 49],
|
|
51
|
+
bgCyan: [46, 49],
|
|
52
|
+
bgWhite: [47, 49],
|
|
53
|
+
|
|
54
|
+
// Bright color
|
|
55
|
+
bgBlackBright: [100, 49],
|
|
56
|
+
bgGray: [100, 49], // Alias of `bgBlackBright`
|
|
57
|
+
bgGrey: [100, 49], // Alias of `bgBlackBright`
|
|
58
|
+
bgRedBright: [101, 49],
|
|
59
|
+
bgGreenBright: [102, 49],
|
|
60
|
+
bgYellowBright: [103, 49],
|
|
61
|
+
bgBlueBright: [104, 49],
|
|
62
|
+
bgMagentaBright: [105, 49],
|
|
63
|
+
bgCyanBright: [106, 49],
|
|
64
|
+
bgWhiteBright: [107, 49],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
9
68
|
function assembleStyles() {
|
|
10
69
|
const codes = new Map();
|
|
11
|
-
const styles = {
|
|
12
|
-
modifier: {
|
|
13
|
-
reset: [0, 0],
|
|
14
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
15
|
-
bold: [1, 22],
|
|
16
|
-
dim: [2, 22],
|
|
17
|
-
italic: [3, 23],
|
|
18
|
-
underline: [4, 24],
|
|
19
|
-
overline: [53, 55],
|
|
20
|
-
inverse: [7, 27],
|
|
21
|
-
hidden: [8, 28],
|
|
22
|
-
strikethrough: [9, 29],
|
|
23
|
-
},
|
|
24
|
-
color: {
|
|
25
|
-
black: [30, 39],
|
|
26
|
-
red: [31, 39],
|
|
27
|
-
green: [32, 39],
|
|
28
|
-
yellow: [33, 39],
|
|
29
|
-
blue: [34, 39],
|
|
30
|
-
magenta: [35, 39],
|
|
31
|
-
cyan: [36, 39],
|
|
32
|
-
white: [37, 39],
|
|
33
|
-
|
|
34
|
-
// Bright color
|
|
35
|
-
blackBright: [90, 39],
|
|
36
|
-
redBright: [91, 39],
|
|
37
|
-
greenBright: [92, 39],
|
|
38
|
-
yellowBright: [93, 39],
|
|
39
|
-
blueBright: [94, 39],
|
|
40
|
-
magentaBright: [95, 39],
|
|
41
|
-
cyanBright: [96, 39],
|
|
42
|
-
whiteBright: [97, 39],
|
|
43
|
-
},
|
|
44
|
-
bgColor: {
|
|
45
|
-
bgBlack: [40, 49],
|
|
46
|
-
bgRed: [41, 49],
|
|
47
|
-
bgGreen: [42, 49],
|
|
48
|
-
bgYellow: [43, 49],
|
|
49
|
-
bgBlue: [44, 49],
|
|
50
|
-
bgMagenta: [45, 49],
|
|
51
|
-
bgCyan: [46, 49],
|
|
52
|
-
bgWhite: [47, 49],
|
|
53
|
-
|
|
54
|
-
// Bright color
|
|
55
|
-
bgBlackBright: [100, 49],
|
|
56
|
-
bgRedBright: [101, 49],
|
|
57
|
-
bgGreenBright: [102, 49],
|
|
58
|
-
bgYellowBright: [103, 49],
|
|
59
|
-
bgBlueBright: [104, 49],
|
|
60
|
-
bgMagentaBright: [105, 49],
|
|
61
|
-
bgCyanBright: [106, 49],
|
|
62
|
-
bgWhiteBright: [107, 49],
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Alias bright black as gray (and grey)
|
|
67
|
-
styles.color.gray = styles.color.blackBright;
|
|
68
|
-
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
69
|
-
styles.color.grey = styles.color.blackBright;
|
|
70
|
-
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
71
70
|
|
|
72
71
|
for (const [groupName, group] of Object.entries(styles)) {
|
|
73
72
|
for (const [styleName, style] of Object.entries(group)) {
|
|
@@ -105,7 +104,7 @@ function assembleStyles() {
|
|
|
105
104
|
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
|
106
105
|
Object.defineProperties(styles, {
|
|
107
106
|
rgbToAnsi256: {
|
|
108
|
-
value
|
|
107
|
+
value(red, green, blue) {
|
|
109
108
|
// We use the extended greyscale palette here, with the exception of
|
|
110
109
|
// black and white. normal palette only has 4 greyscale shades.
|
|
111
110
|
if (red === green && green === blue) {
|
|
@@ -128,13 +127,13 @@ function assembleStyles() {
|
|
|
128
127
|
enumerable: false,
|
|
129
128
|
},
|
|
130
129
|
hexToRgb: {
|
|
131
|
-
value
|
|
132
|
-
const matches = /
|
|
130
|
+
value(hex) {
|
|
131
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
133
132
|
if (!matches) {
|
|
134
133
|
return [0, 0, 0];
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
let
|
|
136
|
+
let [colorString] = matches;
|
|
138
137
|
|
|
139
138
|
if (colorString.length === 3) {
|
|
140
139
|
colorString = [...colorString].map(character => character + character).join('');
|
|
@@ -157,7 +156,7 @@ function assembleStyles() {
|
|
|
157
156
|
enumerable: false,
|
|
158
157
|
},
|
|
159
158
|
ansi256ToAnsi: {
|
|
160
|
-
value
|
|
159
|
+
value(code) {
|
|
161
160
|
if (code < 8) {
|
|
162
161
|
return 30 + code;
|
|
163
162
|
}
|
|
@@ -217,3 +216,8 @@ function assembleStyles() {
|
|
|
217
216
|
const ansiStyles = assembleStyles();
|
|
218
217
|
|
|
219
218
|
export default ansiStyles;
|
|
219
|
+
|
|
220
|
+
export const modifierNames = Object.keys(styles.modifier);
|
|
221
|
+
export const foregroundColorNames = Object.keys(styles.color);
|
|
222
|
+
export const backgroundColorNames = Object.keys(styles.bgColor);
|
|
223
|
+
export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
2
|
|
|
3
|
-
const isBlinkBasedBrowser =
|
|
3
|
+
const isBlinkBasedBrowser = navigator.userAgentData
|
|
4
|
+
? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
|
|
5
|
+
: /\b(Chrome|Chromium)\//.test(navigator.userAgent);
|
|
4
6
|
|
|
5
7
|
const colorSupport = isBlinkBasedBrowser ? {
|
|
6
8
|
level: 1,
|