@depup/chalk 6.0.0-depup.0
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/README.md +25 -0
- package/changes.json +5 -0
- package/license +9 -0
- package/package.json +108 -0
- package/readme.md +331 -0
- package/source/index.d.ts +437 -0
- package/source/index.js +261 -0
- package/source/utilities.js +33 -0
- package/source/vendor/ansi-styles/index.d.ts +299 -0
- package/source/vendor/ansi-styles/index.js +261 -0
- package/source/vendor/supports-color/browser.d.ts +1 -0
- package/source/vendor/supports-color/browser.js +32 -0
- package/source/vendor/supports-color/index.d.ts +55 -0
- package/source/vendor/supports-color/index.js +206 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Note: Each match is kept and `postfix` is inserted after it. `String#replaceAll(substring, substring + postfix)` does the same, but it has to scan the replacement for `$` patterns and it is several times slower on the no-match path that most calls take.
|
|
2
|
+
export function stringReplaceAll(string, substring, postfix) {
|
|
3
|
+
let index = string.indexOf(substring);
|
|
4
|
+
if (index === -1) {
|
|
5
|
+
return string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const substringLength = substring.length;
|
|
9
|
+
let endIndex = 0;
|
|
10
|
+
let returnValue = '';
|
|
11
|
+
do {
|
|
12
|
+
returnValue += string.slice(endIndex, index) + substring + postfix;
|
|
13
|
+
endIndex = index + substringLength;
|
|
14
|
+
index = string.indexOf(substring, endIndex);
|
|
15
|
+
} while (index !== -1);
|
|
16
|
+
|
|
17
|
+
returnValue += string.slice(endIndex);
|
|
18
|
+
return returnValue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
22
|
+
let endIndex = 0;
|
|
23
|
+
let returnValue = '';
|
|
24
|
+
do {
|
|
25
|
+
const isGotCR = string[index - 1] === '\r';
|
|
26
|
+
returnValue += string.slice(endIndex, (isGotCR ? index - 1 : index)) + prefix + (isGotCR ? '\r\n' : '\n') + postfix;
|
|
27
|
+
endIndex = index + 1;
|
|
28
|
+
index = string.indexOf('\n', endIndex);
|
|
29
|
+
} while (index !== -1);
|
|
30
|
+
|
|
31
|
+
returnValue += string.slice(endIndex);
|
|
32
|
+
return returnValue;
|
|
33
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
export type CSPair = { // eslint-disable-line @typescript-eslint/naming-convention
|
|
2
|
+
/**
|
|
3
|
+
The ANSI terminal control sequence for starting this style.
|
|
4
|
+
*/
|
|
5
|
+
readonly open: string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
The ANSI terminal control sequence for ending this style.
|
|
9
|
+
*/
|
|
10
|
+
readonly close: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ColorBase = {
|
|
14
|
+
/**
|
|
15
|
+
The ANSI terminal control sequence for ending this color.
|
|
16
|
+
*/
|
|
17
|
+
readonly close: string;
|
|
18
|
+
|
|
19
|
+
ansi(code: number): string;
|
|
20
|
+
|
|
21
|
+
ansi256(code: number): string;
|
|
22
|
+
|
|
23
|
+
ansi16m(red: number, green: number, blue: number): string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type Modifier = {
|
|
27
|
+
/**
|
|
28
|
+
Resets the current color chain.
|
|
29
|
+
*/
|
|
30
|
+
readonly reset: CSPair;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
Make text bold.
|
|
34
|
+
*/
|
|
35
|
+
readonly bold: CSPair;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
Emitting only a small amount of light.
|
|
39
|
+
*/
|
|
40
|
+
readonly dim: CSPair;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
Make text italic. (Not widely supported)
|
|
44
|
+
*/
|
|
45
|
+
readonly italic: CSPair;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
Put a horizontal line below the text. (Not widely supported)
|
|
49
|
+
*/
|
|
50
|
+
readonly underline: CSPair;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
Put a double horizontal line below the text. (Not widely supported)
|
|
54
|
+
*/
|
|
55
|
+
readonly underlineDouble: CSPair;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
Put a curly horizontal line below the text. (Not widely supported)
|
|
59
|
+
*/
|
|
60
|
+
readonly underlineCurly: CSPair;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
Put a dotted horizontal line below the text. (Not widely supported)
|
|
64
|
+
*/
|
|
65
|
+
readonly underlineDotted: CSPair;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
Put a dashed horizontal line below the text. (Not widely supported)
|
|
69
|
+
*/
|
|
70
|
+
readonly underlineDashed: CSPair;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
Put a horizontal line above the text.
|
|
74
|
+
|
|
75
|
+
Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
|
|
76
|
+
*/
|
|
77
|
+
readonly overline: CSPair;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
Inverse background and foreground colors.
|
|
81
|
+
*/
|
|
82
|
+
readonly inverse: CSPair;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
Prints the text, but makes it invisible.
|
|
86
|
+
*/
|
|
87
|
+
readonly hidden: CSPair;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
Puts a horizontal line through the center of the text. (Not widely supported)
|
|
91
|
+
*/
|
|
92
|
+
readonly strikethrough: CSPair;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type ForegroundColor = {
|
|
96
|
+
readonly black: CSPair;
|
|
97
|
+
readonly red: CSPair;
|
|
98
|
+
readonly green: CSPair;
|
|
99
|
+
readonly yellow: CSPair;
|
|
100
|
+
readonly blue: CSPair;
|
|
101
|
+
readonly cyan: CSPair;
|
|
102
|
+
readonly magenta: CSPair;
|
|
103
|
+
readonly white: CSPair;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
Alias for `blackBright`.
|
|
107
|
+
*/
|
|
108
|
+
readonly gray: CSPair;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
Alias for `blackBright`.
|
|
112
|
+
*/
|
|
113
|
+
readonly grey: CSPair;
|
|
114
|
+
|
|
115
|
+
readonly blackBright: CSPair;
|
|
116
|
+
readonly redBright: CSPair;
|
|
117
|
+
readonly greenBright: CSPair;
|
|
118
|
+
readonly yellowBright: CSPair;
|
|
119
|
+
readonly blueBright: CSPair;
|
|
120
|
+
readonly cyanBright: CSPair;
|
|
121
|
+
readonly magentaBright: CSPair;
|
|
122
|
+
readonly whiteBright: CSPair;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type BackgroundColor = {
|
|
126
|
+
readonly bgBlack: CSPair;
|
|
127
|
+
readonly bgRed: CSPair;
|
|
128
|
+
readonly bgGreen: CSPair;
|
|
129
|
+
readonly bgYellow: CSPair;
|
|
130
|
+
readonly bgBlue: CSPair;
|
|
131
|
+
readonly bgCyan: CSPair;
|
|
132
|
+
readonly bgMagenta: CSPair;
|
|
133
|
+
readonly bgWhite: CSPair;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
Alias for `bgBlackBright`.
|
|
137
|
+
*/
|
|
138
|
+
readonly bgGray: CSPair;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
Alias for `bgBlackBright`.
|
|
142
|
+
*/
|
|
143
|
+
readonly bgGrey: CSPair;
|
|
144
|
+
|
|
145
|
+
readonly bgBlackBright: CSPair;
|
|
146
|
+
readonly bgRedBright: CSPair;
|
|
147
|
+
readonly bgGreenBright: CSPair;
|
|
148
|
+
readonly bgYellowBright: CSPair;
|
|
149
|
+
readonly bgBlueBright: CSPair;
|
|
150
|
+
readonly bgCyanBright: CSPair;
|
|
151
|
+
readonly bgMagentaBright: CSPair;
|
|
152
|
+
readonly bgWhiteBright: CSPair;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export type UnderlineColor = {
|
|
156
|
+
readonly underlineBlack: CSPair;
|
|
157
|
+
readonly underlineRed: CSPair;
|
|
158
|
+
readonly underlineGreen: CSPair;
|
|
159
|
+
readonly underlineYellow: CSPair;
|
|
160
|
+
readonly underlineBlue: CSPair;
|
|
161
|
+
readonly underlineCyan: CSPair;
|
|
162
|
+
readonly underlineMagenta: CSPair;
|
|
163
|
+
readonly underlineWhite: CSPair;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
Alias for `underlineBlackBright`.
|
|
167
|
+
*/
|
|
168
|
+
readonly underlineGray: CSPair;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
Alias for `underlineBlackBright`.
|
|
172
|
+
*/
|
|
173
|
+
readonly underlineGrey: CSPair;
|
|
174
|
+
|
|
175
|
+
readonly underlineBlackBright: CSPair;
|
|
176
|
+
readonly underlineRedBright: CSPair;
|
|
177
|
+
readonly underlineGreenBright: CSPair;
|
|
178
|
+
readonly underlineYellowBright: CSPair;
|
|
179
|
+
readonly underlineBlueBright: CSPair;
|
|
180
|
+
readonly underlineCyanBright: CSPair;
|
|
181
|
+
readonly underlineMagentaBright: CSPair;
|
|
182
|
+
readonly underlineWhiteBright: CSPair;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export type ConvertColor = {
|
|
186
|
+
/**
|
|
187
|
+
Convert from the RGB color space to the ANSI 256 color space.
|
|
188
|
+
|
|
189
|
+
@param red - (`0...255`)
|
|
190
|
+
@param green - (`0...255`)
|
|
191
|
+
@param blue - (`0...255`)
|
|
192
|
+
*/
|
|
193
|
+
rgbToAnsi256(red: number, green: number, blue: number): number;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
Convert from the RGB HEX color space to the RGB color space.
|
|
197
|
+
|
|
198
|
+
@param hex - A hexadecimal string containing RGB data.
|
|
199
|
+
*/
|
|
200
|
+
hexToRgb(hex: string): [red: number, green: number, blue: number];
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
Convert from the RGB HEX color space to the ANSI 256 color space.
|
|
204
|
+
|
|
205
|
+
@param hex - A hexadecimal string containing RGB data.
|
|
206
|
+
*/
|
|
207
|
+
hexToAnsi256(hex: string): number;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
Convert from the ANSI 256 color space to the ANSI 16 color space.
|
|
211
|
+
|
|
212
|
+
@param code - A number representing the ANSI 256 color.
|
|
213
|
+
*/
|
|
214
|
+
ansi256ToAnsi(code: number): number;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
Convert from the RGB color space to the ANSI 16 color space.
|
|
218
|
+
|
|
219
|
+
@param red - (`0...255`)
|
|
220
|
+
@param green - (`0...255`)
|
|
221
|
+
@param blue - (`0...255`)
|
|
222
|
+
*/
|
|
223
|
+
rgbToAnsi(red: number, green: number, blue: number): number;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
Convert from the RGB HEX color space to the ANSI 16 color space.
|
|
227
|
+
|
|
228
|
+
@param hex - A hexadecimal string containing RGB data.
|
|
229
|
+
*/
|
|
230
|
+
hexToAnsi(hex: string): number;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
Basic modifier names.
|
|
235
|
+
*/
|
|
236
|
+
export type ModifierName = keyof Modifier;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
Basic foreground color names.
|
|
240
|
+
|
|
241
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
242
|
+
*/
|
|
243
|
+
export type ForegroundColorName = keyof ForegroundColor;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
Basic background color names.
|
|
247
|
+
|
|
248
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
249
|
+
*/
|
|
250
|
+
export type BackgroundColorName = keyof BackgroundColor;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
Basic underline color names.
|
|
254
|
+
|
|
255
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
256
|
+
*/
|
|
257
|
+
export type UnderlineColorName = keyof UnderlineColor;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
Basic color names. The combination of foreground and background color names.
|
|
261
|
+
|
|
262
|
+
[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
|
|
263
|
+
*/
|
|
264
|
+
export type ColorName = ForegroundColorName | BackgroundColorName;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
Basic modifier names.
|
|
268
|
+
*/
|
|
269
|
+
export const modifierNames: readonly ModifierName[];
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
Basic foreground color names.
|
|
273
|
+
*/
|
|
274
|
+
export const foregroundColorNames: readonly ForegroundColorName[];
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
Basic background color names.
|
|
278
|
+
*/
|
|
279
|
+
export const backgroundColorNames: readonly BackgroundColorName[];
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
Basic underline color names.
|
|
283
|
+
*/
|
|
284
|
+
export const underlineColorNames: readonly UnderlineColorName[];
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
Basic color names. The combination of foreground and background color names.
|
|
288
|
+
*/
|
|
289
|
+
export const colorNames: readonly ColorName[];
|
|
290
|
+
|
|
291
|
+
declare const ansiStyles: {
|
|
292
|
+
readonly modifier: Modifier;
|
|
293
|
+
readonly color: ColorBase & ForegroundColor;
|
|
294
|
+
readonly bgColor: ColorBase & BackgroundColor;
|
|
295
|
+
readonly underlineColor: ColorBase & UnderlineColor;
|
|
296
|
+
readonly codes: ReadonlyMap<number, number>;
|
|
297
|
+
} & ForegroundColor & BackgroundColor & UnderlineColor & Modifier & ConvertColor;
|
|
298
|
+
|
|
299
|
+
export default ansiStyles;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
const ANSI_BACKGROUND_OFFSET = 10;
|
|
2
|
+
const ANSI_UNDERLINE_OFFSET = 20;
|
|
3
|
+
|
|
4
|
+
const wrapAnsi16 = (offset = 0) => code => `\u{1B}[${code + offset}m`;
|
|
5
|
+
|
|
6
|
+
const wrapAnsi256 = (offset = 0) => code => `\u{1B}[${38 + offset};5;${code}m`;
|
|
7
|
+
|
|
8
|
+
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u{1B}[${38 + offset};2;${red};${green};${blue}m`;
|
|
9
|
+
|
|
10
|
+
// `SGR 58` has no basic 16-color form, so the basic color code is mapped to its palette index instead.
|
|
11
|
+
const wrapUnderlineAnsi = code => `\u{1B}[58;5;${code < 90 ? code - 30 : code - 90 + 8}m`;
|
|
12
|
+
|
|
13
|
+
const styles = {
|
|
14
|
+
modifier: {
|
|
15
|
+
reset: [0, 0],
|
|
16
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
17
|
+
bold: [1, 22],
|
|
18
|
+
dim: [2, 22],
|
|
19
|
+
italic: [3, 23],
|
|
20
|
+
underline: [4, 24],
|
|
21
|
+
// Extended underline styles (`SGR 4:x` sub-parameters). Not in upstream `ansi-styles`.
|
|
22
|
+
underlineDouble: ['4:2', 24],
|
|
23
|
+
underlineCurly: ['4:3', 24],
|
|
24
|
+
underlineDotted: ['4:4', 24],
|
|
25
|
+
underlineDashed: ['4:5', 24],
|
|
26
|
+
overline: [53, 55],
|
|
27
|
+
inverse: [7, 27],
|
|
28
|
+
hidden: [8, 28],
|
|
29
|
+
strikethrough: [9, 29],
|
|
30
|
+
},
|
|
31
|
+
color: {
|
|
32
|
+
black: [30, 39],
|
|
33
|
+
red: [31, 39],
|
|
34
|
+
green: [32, 39],
|
|
35
|
+
yellow: [33, 39],
|
|
36
|
+
blue: [34, 39],
|
|
37
|
+
magenta: [35, 39],
|
|
38
|
+
cyan: [36, 39],
|
|
39
|
+
white: [37, 39],
|
|
40
|
+
|
|
41
|
+
// Bright color
|
|
42
|
+
blackBright: [90, 39],
|
|
43
|
+
gray: [90, 39], // Alias of `blackBright`
|
|
44
|
+
grey: [90, 39], // Alias of `blackBright`
|
|
45
|
+
redBright: [91, 39],
|
|
46
|
+
greenBright: [92, 39],
|
|
47
|
+
yellowBright: [93, 39],
|
|
48
|
+
blueBright: [94, 39],
|
|
49
|
+
magentaBright: [95, 39],
|
|
50
|
+
cyanBright: [96, 39],
|
|
51
|
+
whiteBright: [97, 39],
|
|
52
|
+
},
|
|
53
|
+
bgColor: {
|
|
54
|
+
bgBlack: [40, 49],
|
|
55
|
+
bgRed: [41, 49],
|
|
56
|
+
bgGreen: [42, 49],
|
|
57
|
+
bgYellow: [43, 49],
|
|
58
|
+
bgBlue: [44, 49],
|
|
59
|
+
bgMagenta: [45, 49],
|
|
60
|
+
bgCyan: [46, 49],
|
|
61
|
+
bgWhite: [47, 49],
|
|
62
|
+
|
|
63
|
+
// Bright color
|
|
64
|
+
bgBlackBright: [100, 49],
|
|
65
|
+
bgGray: [100, 49], // Alias of `bgBlackBright`
|
|
66
|
+
bgGrey: [100, 49], // Alias of `bgBlackBright`
|
|
67
|
+
bgRedBright: [101, 49],
|
|
68
|
+
bgGreenBright: [102, 49],
|
|
69
|
+
bgYellowBright: [103, 49],
|
|
70
|
+
bgBlueBright: [104, 49],
|
|
71
|
+
bgMagentaBright: [105, 49],
|
|
72
|
+
bgCyanBright: [106, 49],
|
|
73
|
+
bgWhiteBright: [107, 49],
|
|
74
|
+
},
|
|
75
|
+
// Underline color (`SGR 58`/`59`). Not in upstream `ansi-styles`.
|
|
76
|
+
underlineColor: {
|
|
77
|
+
underlineBlack: ['58;5;0', 59],
|
|
78
|
+
underlineRed: ['58;5;1', 59],
|
|
79
|
+
underlineGreen: ['58;5;2', 59],
|
|
80
|
+
underlineYellow: ['58;5;3', 59],
|
|
81
|
+
underlineBlue: ['58;5;4', 59],
|
|
82
|
+
underlineMagenta: ['58;5;5', 59],
|
|
83
|
+
underlineCyan: ['58;5;6', 59],
|
|
84
|
+
underlineWhite: ['58;5;7', 59],
|
|
85
|
+
|
|
86
|
+
// Bright color
|
|
87
|
+
underlineBlackBright: ['58;5;8', 59],
|
|
88
|
+
underlineGray: ['58;5;8', 59], // Alias of `underlineBlackBright`
|
|
89
|
+
underlineGrey: ['58;5;8', 59], // Alias of `underlineBlackBright`
|
|
90
|
+
underlineRedBright: ['58;5;9', 59],
|
|
91
|
+
underlineGreenBright: ['58;5;10', 59],
|
|
92
|
+
underlineYellowBright: ['58;5;11', 59],
|
|
93
|
+
underlineBlueBright: ['58;5;12', 59],
|
|
94
|
+
underlineMagentaBright: ['58;5;13', 59],
|
|
95
|
+
underlineCyanBright: ['58;5;14', 59],
|
|
96
|
+
underlineWhiteBright: ['58;5;15', 59],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const modifierNames = Object.keys(styles.modifier);
|
|
101
|
+
export const foregroundColorNames = Object.keys(styles.color);
|
|
102
|
+
export const backgroundColorNames = Object.keys(styles.bgColor);
|
|
103
|
+
export const underlineColorNames = Object.keys(styles.underlineColor);
|
|
104
|
+
export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
105
|
+
|
|
106
|
+
function assembleStyles() {
|
|
107
|
+
const codes = new Map();
|
|
108
|
+
|
|
109
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
110
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
111
|
+
styles[styleName] = {
|
|
112
|
+
open: `\u{1B}[${style[0]}m`,
|
|
113
|
+
close: `\u{1B}[${style[1]}m`,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
group[styleName] = styles[styleName];
|
|
117
|
+
|
|
118
|
+
// Only the leading SGR parameter identifies a style, so `4:3` and `58;5;1` are keyed as `4` and `58`.
|
|
119
|
+
codes.set(Number.parseInt(style[0], 10), style[1]);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
Object.defineProperty(styles, groupName, {
|
|
123
|
+
value: group,
|
|
124
|
+
enumerable: false,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Object.defineProperty(styles, 'codes', {
|
|
129
|
+
value: codes,
|
|
130
|
+
enumerable: false,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
styles.color.close = '\u{1B}[39m';
|
|
134
|
+
styles.bgColor.close = '\u{1B}[49m';
|
|
135
|
+
styles.underlineColor.close = '\u{1B}[59m';
|
|
136
|
+
|
|
137
|
+
styles.color.ansi = wrapAnsi16();
|
|
138
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
139
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
140
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
141
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
142
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
143
|
+
styles.underlineColor.ansi = wrapUnderlineAnsi;
|
|
144
|
+
styles.underlineColor.ansi256 = wrapAnsi256(ANSI_UNDERLINE_OFFSET);
|
|
145
|
+
styles.underlineColor.ansi16m = wrapAnsi16m(ANSI_UNDERLINE_OFFSET);
|
|
146
|
+
|
|
147
|
+
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
|
148
|
+
Object.defineProperties(styles, {
|
|
149
|
+
rgbToAnsi256: {
|
|
150
|
+
value(red, green, blue) {
|
|
151
|
+
// We use the extended greyscale palette here, with the exception of
|
|
152
|
+
// black and white. normal palette only has 4 greyscale shades.
|
|
153
|
+
if (red === green && green === blue) {
|
|
154
|
+
if (red < 8) {
|
|
155
|
+
return 16;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (red > 248) {
|
|
159
|
+
return 231;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return Math.round(((red - 8) / 247) * 24) + 232;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return 16
|
|
166
|
+
+ (36 * Math.round(red / 255 * 5))
|
|
167
|
+
+ (6 * Math.round(green / 255 * 5))
|
|
168
|
+
+ Math.round(blue / 255 * 5);
|
|
169
|
+
},
|
|
170
|
+
enumerable: false,
|
|
171
|
+
},
|
|
172
|
+
hexToRgb: {
|
|
173
|
+
value(hex) {
|
|
174
|
+
const matches = /[\da-f]{6}|[\da-f]{3}/i.exec(hex.toString(16));
|
|
175
|
+
if (!matches) {
|
|
176
|
+
return [0, 0, 0];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let [colorString] = matches;
|
|
180
|
+
|
|
181
|
+
if (colorString.length === 3) {
|
|
182
|
+
colorString = [...colorString].map(character => character + character).join('');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const integer = Number.parseInt(colorString, 16);
|
|
186
|
+
|
|
187
|
+
return [
|
|
188
|
+
/* eslint-disable no-bitwise -- We need the speed */
|
|
189
|
+
(integer >> 16) & 0xFF,
|
|
190
|
+
(integer >> 8) & 0xFF,
|
|
191
|
+
integer & 0xFF,
|
|
192
|
+
/* eslint-enable no-bitwise */
|
|
193
|
+
];
|
|
194
|
+
},
|
|
195
|
+
enumerable: false,
|
|
196
|
+
},
|
|
197
|
+
hexToAnsi256: {
|
|
198
|
+
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
199
|
+
enumerable: false,
|
|
200
|
+
},
|
|
201
|
+
ansi256ToAnsi: {
|
|
202
|
+
value(code) {
|
|
203
|
+
if (code < 8) {
|
|
204
|
+
return 30 + code;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (code < 16) {
|
|
208
|
+
return 90 + (code - 8);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let red;
|
|
212
|
+
let green;
|
|
213
|
+
let blue;
|
|
214
|
+
|
|
215
|
+
if (code >= 232) {
|
|
216
|
+
red = (((code - 232) * 10) + 8) / 255;
|
|
217
|
+
green = red;
|
|
218
|
+
blue = red;
|
|
219
|
+
} else {
|
|
220
|
+
code -= 16;
|
|
221
|
+
|
|
222
|
+
const remainder = code % 36;
|
|
223
|
+
|
|
224
|
+
red = Math.floor(code / 36) / 5;
|
|
225
|
+
green = Math.floor(remainder / 6) / 5;
|
|
226
|
+
blue = (remainder % 6) / 5;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const value = Math.max(red, green, blue) * 2;
|
|
230
|
+
|
|
231
|
+
if (value === 0) {
|
|
232
|
+
return 30;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// eslint-disable-next-line no-bitwise
|
|
236
|
+
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
|
|
237
|
+
|
|
238
|
+
if (value === 2) {
|
|
239
|
+
result += 60;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return result;
|
|
243
|
+
},
|
|
244
|
+
enumerable: false,
|
|
245
|
+
},
|
|
246
|
+
rgbToAnsi: {
|
|
247
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
248
|
+
enumerable: false,
|
|
249
|
+
},
|
|
250
|
+
hexToAnsi: {
|
|
251
|
+
value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
252
|
+
enumerable: false,
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
return styles;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const ansiStyles = assembleStyles();
|
|
260
|
+
|
|
261
|
+
export default ansiStyles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {default} from './index.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const level = (() => {
|
|
2
|
+
if (!('navigator' in globalThis)) {
|
|
3
|
+
return 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
if (globalThis.navigator.userAgentData) {
|
|
7
|
+
const brand = globalThis.navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
|
|
8
|
+
if (brand?.version > 93) {
|
|
9
|
+
return 3;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (/\b(?:Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return 0;
|
|
18
|
+
})();
|
|
19
|
+
|
|
20
|
+
const colorSupport = level !== 0 && {
|
|
21
|
+
level,
|
|
22
|
+
hasBasic: true,
|
|
23
|
+
has256: level >= 2,
|
|
24
|
+
has16m: level >= 3,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const supportsColor = {
|
|
28
|
+
stdout: colorSupport,
|
|
29
|
+
stderr: colorSupport,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default supportsColor;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type {WriteStream} from 'node:tty';
|
|
2
|
+
|
|
3
|
+
export type Options = {
|
|
4
|
+
/**
|
|
5
|
+
Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.
|
|
6
|
+
|
|
7
|
+
@default true
|
|
8
|
+
*/
|
|
9
|
+
readonly sniffFlags?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
Levels:
|
|
14
|
+
- `0` - All colors disabled.
|
|
15
|
+
- `1` - Basic 16 colors support.
|
|
16
|
+
- `2` - ANSI 256 colors support.
|
|
17
|
+
- `3` - Truecolor 16 million colors support.
|
|
18
|
+
*/
|
|
19
|
+
export type ColorSupportLevel = 0 | 1 | 2 | 3;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
Detect whether the terminal supports color.
|
|
23
|
+
*/
|
|
24
|
+
export type ColorSupport = {
|
|
25
|
+
/**
|
|
26
|
+
The color level.
|
|
27
|
+
*/
|
|
28
|
+
level: ColorSupportLevel;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
Whether basic 16 colors are supported.
|
|
32
|
+
*/
|
|
33
|
+
hasBasic: boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
Whether ANSI 256 colors are supported.
|
|
37
|
+
*/
|
|
38
|
+
has256: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
Whether Truecolor 16 million colors are supported.
|
|
42
|
+
*/
|
|
43
|
+
has16m: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type ColorInfo = ColorSupport | false;
|
|
47
|
+
|
|
48
|
+
export function createSupportsColor(stream?: WriteStream, options?: Options): ColorInfo;
|
|
49
|
+
|
|
50
|
+
declare const supportsColor: {
|
|
51
|
+
stdout: ColorInfo;
|
|
52
|
+
stderr: ColorInfo;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default supportsColor;
|