ansi-styles 5.0.0 → 6.1.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/index.d.ts +185 -155
- package/index.js +105 -43
- package/license +1 -1
- package/package.json +7 -6
- package/readme.md +32 -20
package/index.d.ts
CHANGED
@@ -1,160 +1,190 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
1
|
+
export interface CSPair {
|
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 interface 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 interface 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
|
+
Make text underline. (Not widely supported)
|
49
|
+
*/
|
50
|
+
readonly underline: CSPair;
|
51
|
+
|
52
|
+
/**
|
53
|
+
Make text overline.
|
54
|
+
|
55
|
+
Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.
|
56
|
+
*/
|
57
|
+
readonly overline: CSPair;
|
58
|
+
|
59
|
+
/**
|
60
|
+
Inverse background and foreground colors.
|
61
|
+
*/
|
62
|
+
readonly inverse: CSPair;
|
63
|
+
|
64
|
+
/**
|
65
|
+
Prints the text, but makes it invisible.
|
66
|
+
*/
|
67
|
+
readonly hidden: CSPair;
|
68
|
+
|
69
|
+
/**
|
70
|
+
Puts a horizontal line through the center of the text. (Not widely supported)
|
71
|
+
*/
|
72
|
+
readonly strikethrough: CSPair;
|
73
|
+
}
|
74
|
+
|
75
|
+
export interface ForegroundColor {
|
76
|
+
readonly black: CSPair;
|
77
|
+
readonly red: CSPair;
|
78
|
+
readonly green: CSPair;
|
79
|
+
readonly yellow: CSPair;
|
80
|
+
readonly blue: CSPair;
|
81
|
+
readonly cyan: CSPair;
|
82
|
+
readonly magenta: CSPair;
|
83
|
+
readonly white: CSPair;
|
84
|
+
|
85
|
+
/**
|
86
|
+
Alias for `blackBright`.
|
87
|
+
*/
|
88
|
+
readonly gray: CSPair;
|
89
|
+
|
90
|
+
/**
|
91
|
+
Alias for `blackBright`.
|
92
|
+
*/
|
93
|
+
readonly grey: CSPair;
|
94
|
+
|
95
|
+
readonly blackBright: CSPair;
|
96
|
+
readonly redBright: CSPair;
|
97
|
+
readonly greenBright: CSPair;
|
98
|
+
readonly yellowBright: CSPair;
|
99
|
+
readonly blueBright: CSPair;
|
100
|
+
readonly cyanBright: CSPair;
|
101
|
+
readonly magentaBright: CSPair;
|
102
|
+
readonly whiteBright: CSPair;
|
103
|
+
}
|
104
|
+
|
105
|
+
export interface BackgroundColor {
|
106
|
+
readonly bgBlack: CSPair;
|
107
|
+
readonly bgRed: CSPair;
|
108
|
+
readonly bgGreen: CSPair;
|
109
|
+
readonly bgYellow: CSPair;
|
110
|
+
readonly bgBlue: CSPair;
|
111
|
+
readonly bgCyan: CSPair;
|
112
|
+
readonly bgMagenta: CSPair;
|
113
|
+
readonly bgWhite: CSPair;
|
114
|
+
|
115
|
+
/**
|
116
|
+
Alias for `bgBlackBright`.
|
117
|
+
*/
|
118
|
+
readonly bgGray: CSPair;
|
119
|
+
|
120
|
+
/**
|
121
|
+
Alias for `bgBlackBright`.
|
122
|
+
*/
|
123
|
+
readonly bgGrey: CSPair;
|
124
|
+
|
125
|
+
readonly bgBlackBright: CSPair;
|
126
|
+
readonly bgRedBright: CSPair;
|
127
|
+
readonly bgGreenBright: CSPair;
|
128
|
+
readonly bgYellowBright: CSPair;
|
129
|
+
readonly bgBlueBright: CSPair;
|
130
|
+
readonly bgCyanBright: CSPair;
|
131
|
+
readonly bgMagentaBright: CSPair;
|
132
|
+
readonly bgWhiteBright: CSPair;
|
133
|
+
}
|
134
|
+
|
135
|
+
export interface ConvertColor {
|
136
|
+
/**
|
137
|
+
Convert from the RGB color space to the ANSI 256 color space.
|
138
|
+
|
139
|
+
@param red - (`0...255`)
|
140
|
+
@param green - (`0...255`)
|
141
|
+
@param blue - (`0...255`)
|
142
|
+
*/
|
143
|
+
rgbToAnsi256(red: number, green: number, blue: number): number;
|
144
|
+
|
145
|
+
/**
|
146
|
+
Convert from the RGB HEX color space to the RGB color space.
|
147
|
+
|
148
|
+
@param hex - A hexadecimal string containing RGB data.
|
149
|
+
*/
|
150
|
+
hexToRgb(hex: string): [red: number, green: number, blue: number];
|
151
|
+
|
152
|
+
/**
|
153
|
+
Convert from the RGB HEX color space to the ANSI 256 color space.
|
154
|
+
|
155
|
+
@param hex - A hexadecimal string containing RGB data.
|
156
|
+
*/
|
157
|
+
hexToAnsi256(hex: string): number;
|
158
|
+
|
159
|
+
/**
|
160
|
+
Convert from the ANSI 256 color space to the ANSI 16 color space.
|
161
|
+
|
162
|
+
@param code - A number representing the ANSI 256 color.
|
163
|
+
*/
|
164
|
+
ansi256ToAnsi(code: number): number;
|
165
|
+
|
166
|
+
/**
|
167
|
+
Convert from the RGB color space to the ANSI 16 color space.
|
168
|
+
|
169
|
+
@param red - (`0...255`)
|
170
|
+
@param green - (`0...255`)
|
171
|
+
@param blue - (`0...255`)
|
172
|
+
*/
|
173
|
+
rgbToAnsi(red: number, green: number, blue: number): number;
|
174
|
+
|
175
|
+
/**
|
176
|
+
Convert from the RGB HEX color space to the ANSI 16 color space.
|
177
|
+
|
178
|
+
@param hex - A hexadecimal string containing RGB data.
|
179
|
+
*/
|
180
|
+
hexToAnsi(hex: string): number;
|
151
181
|
}
|
152
182
|
|
153
183
|
declare const ansiStyles: {
|
154
|
-
readonly modifier:
|
155
|
-
readonly color:
|
156
|
-
readonly bgColor:
|
184
|
+
readonly modifier: Modifier;
|
185
|
+
readonly color: ColorBase & ForegroundColor;
|
186
|
+
readonly bgColor: ColorBase & BackgroundColor;
|
157
187
|
readonly codes: ReadonlyMap<number, number>;
|
158
|
-
} &
|
188
|
+
} & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
|
159
189
|
|
160
|
-
export
|
190
|
+
export default ansiStyles;
|
package/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
1
|
const ANSI_BACKGROUND_OFFSET = 10;
|
4
2
|
|
3
|
+
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
|
4
|
+
|
5
5
|
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`;
|
@@ -16,6 +16,7 @@ function assembleStyles() {
|
|
16
16
|
dim: [2, 22],
|
17
17
|
italic: [3, 23],
|
18
18
|
underline: [4, 24],
|
19
|
+
overline: [53, 55],
|
19
20
|
inverse: [7, 27],
|
20
21
|
hidden: [8, 28],
|
21
22
|
strikethrough: [9, 29]
|
@@ -94,61 +95,122 @@ function assembleStyles() {
|
|
94
95
|
styles.color.close = '\u001B[39m';
|
95
96
|
styles.bgColor.close = '\u001B[49m';
|
96
97
|
|
98
|
+
styles.color.ansi = wrapAnsi16();
|
97
99
|
styles.color.ansi256 = wrapAnsi256();
|
98
100
|
styles.color.ansi16m = wrapAnsi16m();
|
101
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
99
102
|
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
100
103
|
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
101
104
|
|
102
105
|
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
106
|
+
Object.defineProperties(styles, {
|
107
|
+
rgbToAnsi256: {
|
108
|
+
value: (red, green, blue) => {
|
109
|
+
// We use the extended greyscale palette here, with the exception of
|
110
|
+
// black and white. normal palette only has 4 greyscale shades.
|
111
|
+
if (red === green && green === blue) {
|
112
|
+
if (red < 8) {
|
113
|
+
return 16;
|
114
|
+
}
|
115
|
+
|
116
|
+
if (red > 248) {
|
117
|
+
return 231;
|
118
|
+
}
|
119
|
+
|
120
|
+
return Math.round(((red - 8) / 247) * 24) + 232;
|
121
|
+
}
|
122
|
+
|
123
|
+
return 16 +
|
124
|
+
(36 * Math.round(red / 255 * 5)) +
|
125
|
+
(6 * Math.round(green / 255 * 5)) +
|
126
|
+
Math.round(blue / 255 * 5);
|
127
|
+
},
|
128
|
+
enumerable: false
|
129
|
+
},
|
130
|
+
hexToRgb: {
|
131
|
+
value: hex => {
|
132
|
+
const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
|
133
|
+
if (!matches) {
|
134
|
+
return [0, 0, 0];
|
135
|
+
}
|
136
|
+
|
137
|
+
let {colorString} = matches.groups;
|
138
|
+
|
139
|
+
if (colorString.length === 3) {
|
140
|
+
colorString = colorString.split('').map(character => character + character).join('');
|
141
|
+
}
|
142
|
+
|
143
|
+
const integer = Number.parseInt(colorString, 16);
|
144
|
+
|
145
|
+
return [
|
146
|
+
(integer >> 16) & 0xFF,
|
147
|
+
(integer >> 8) & 0xFF,
|
148
|
+
integer & 0xFF
|
149
|
+
];
|
150
|
+
},
|
151
|
+
enumerable: false
|
152
|
+
},
|
153
|
+
hexToAnsi256: {
|
154
|
+
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
155
|
+
enumerable: false
|
156
|
+
},
|
157
|
+
ansi256ToAnsi: {
|
158
|
+
value: code => {
|
159
|
+
if (code < 8) {
|
160
|
+
return 30 + code;
|
161
|
+
}
|
117
162
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
Math.round(blue / 255 * 5);
|
122
|
-
};
|
163
|
+
if (code < 16) {
|
164
|
+
return 90 + (code - 8);
|
165
|
+
}
|
123
166
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
return [0, 0, 0];
|
128
|
-
}
|
167
|
+
let red;
|
168
|
+
let green;
|
169
|
+
let blue;
|
129
170
|
|
130
|
-
|
171
|
+
if (code >= 232) {
|
172
|
+
red = (((code - 232) * 10) + 8) / 255;
|
173
|
+
green = red;
|
174
|
+
blue = red;
|
175
|
+
} else {
|
176
|
+
code -= 16;
|
131
177
|
|
132
|
-
|
133
|
-
colorString = colorString.split('').map(character => character + character).join('');
|
134
|
-
}
|
178
|
+
const remainder = code % 36;
|
135
179
|
|
136
|
-
|
180
|
+
red = Math.floor(code / 36) / 5;
|
181
|
+
green = Math.floor(remainder / 6) / 5;
|
182
|
+
blue = (remainder % 6) / 5;
|
183
|
+
}
|
137
184
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
185
|
+
const value = Math.max(red, green, blue) * 2;
|
186
|
+
|
187
|
+
if (value === 0) {
|
188
|
+
return 30;
|
189
|
+
}
|
190
|
+
|
191
|
+
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
|
144
192
|
|
145
|
-
|
193
|
+
if (value === 2) {
|
194
|
+
result += 60;
|
195
|
+
}
|
196
|
+
|
197
|
+
return result;
|
198
|
+
},
|
199
|
+
enumerable: false
|
200
|
+
},
|
201
|
+
rgbToAnsi: {
|
202
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
203
|
+
enumerable: false
|
204
|
+
},
|
205
|
+
hexToAnsi: {
|
206
|
+
value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
207
|
+
enumerable: false
|
208
|
+
}
|
209
|
+
});
|
146
210
|
|
147
211
|
return styles;
|
148
212
|
}
|
149
213
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
get: assembleStyles
|
154
|
-
});
|
214
|
+
const ansiStyles = assembleStyles();
|
215
|
+
|
216
|
+
export default ansiStyles;
|
package/license
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
MIT License
|
2
2
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
6
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ansi-styles",
|
3
|
-
"version": "
|
3
|
+
"version": "6.1.0",
|
4
4
|
"description": "ANSI escape codes for styling strings in the terminal",
|
5
5
|
"license": "MIT",
|
6
6
|
"repository": "chalk/ansi-styles",
|
@@ -10,8 +10,10 @@
|
|
10
10
|
"email": "sindresorhus@gmail.com",
|
11
11
|
"url": "https://sindresorhus.com"
|
12
12
|
},
|
13
|
+
"type": "module",
|
14
|
+
"exports": "./index.js",
|
13
15
|
"engines": {
|
14
|
-
"node": ">=
|
16
|
+
"node": ">=12"
|
15
17
|
},
|
16
18
|
"scripts": {
|
17
19
|
"test": "xo && ava && tsd",
|
@@ -44,10 +46,9 @@
|
|
44
46
|
"text"
|
45
47
|
],
|
46
48
|
"devDependencies": {
|
47
|
-
"
|
48
|
-
"ava": "^2.3.0",
|
49
|
+
"ava": "^3.15.0",
|
49
50
|
"svg-term-cli": "^2.1.1",
|
50
|
-
"tsd": "^0.
|
51
|
-
"xo": "^0.
|
51
|
+
"tsd": "^0.14.0",
|
52
|
+
"xo": "^0.38.2"
|
52
53
|
}
|
53
54
|
}
|
package/readme.md
CHANGED
@@ -15,18 +15,19 @@ $ npm install ansi-styles
|
|
15
15
|
## Usage
|
16
16
|
|
17
17
|
```js
|
18
|
-
|
18
|
+
import styles from 'ansi-styles';
|
19
19
|
|
20
|
-
console.log(`${
|
20
|
+
console.log(`${styles.green.open}Hello world!${styles.green.close}`);
|
21
21
|
|
22
22
|
|
23
|
-
// Color conversion between
|
24
|
-
// NOTE:
|
25
|
-
// may be degraded to fit
|
23
|
+
// Color conversion between 256/truecolor
|
24
|
+
// NOTE: When converting from truecolor to 256 colors, the original color
|
25
|
+
// may be degraded to fit the new color palette. This means terminals
|
26
26
|
// that do not support 16 million colors will best-match the
|
27
27
|
// original color.
|
28
|
-
console.log(`${
|
29
|
-
console.log(`${
|
28
|
+
console.log(`${styles.color.ansi(styles.rgbToAnsi(199, 20, 250))}Hello World${styles.color.close}`)
|
29
|
+
console.log(`${styles.color.ansi256(styles.rgbToAnsi256(199, 20, 250))}Hello World${styles.color.close}`)
|
30
|
+
console.log(`${styles.color.ansi16m(...styles.hexToRgb('#abcdef'))}Hello World${styles.color.close}`)
|
30
31
|
```
|
31
32
|
|
32
33
|
## API
|
@@ -42,6 +43,7 @@ Each style has an `open` and `close` property.
|
|
42
43
|
- `dim`
|
43
44
|
- `italic` *(Not widely supported)*
|
44
45
|
- `underline`
|
46
|
+
- `overline` *Supported on VTE-based terminals, the GNOME terminal, mintty, and Git Bash.*
|
45
47
|
- `inverse`
|
46
48
|
- `hidden`
|
47
49
|
- `strikethrough` *(Not widely supported)*
|
@@ -88,43 +90,53 @@ Each style has an `open` and `close` property.
|
|
88
90
|
|
89
91
|
By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
|
90
92
|
|
91
|
-
- `
|
92
|
-
- `
|
93
|
-
- `
|
93
|
+
- `styles.modifier`
|
94
|
+
- `styles.color`
|
95
|
+
- `styles.bgColor`
|
94
96
|
|
95
97
|
###### Example
|
96
98
|
|
97
99
|
```js
|
98
|
-
|
100
|
+
import styles from 'ansi-styles';
|
101
|
+
|
102
|
+
console.log(styles.color.green.open);
|
99
103
|
```
|
100
104
|
|
101
|
-
Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `
|
105
|
+
Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `styles.codes`, which returns a `Map` with the open codes as keys and close codes as values.
|
102
106
|
|
103
107
|
###### Example
|
104
108
|
|
105
109
|
```js
|
106
|
-
|
110
|
+
import styles from 'ansi-styles';
|
111
|
+
|
112
|
+
console.log(styles.codes.get(36));
|
107
113
|
//=> 39
|
108
114
|
```
|
109
115
|
|
110
|
-
##
|
116
|
+
## 16 / 256 / 16 million (TrueColor) support
|
111
117
|
|
112
|
-
`ansi-styles` allows converting between various color formats and ANSI escapes, with support for 256 and 16 million colors.
|
118
|
+
`ansi-styles` allows converting between various color formats and ANSI escapes, with support for 16, 256 and [16 million colors](https://gist.github.com/XVilka/8346728).
|
113
119
|
|
114
|
-
The following color spaces
|
120
|
+
The following color spaces are supported:
|
115
121
|
|
116
122
|
- `rgb`
|
117
123
|
- `hex`
|
118
124
|
- `ansi256`
|
125
|
+
- `ansi`
|
119
126
|
|
120
127
|
To use these, call the associated conversion function with the intended output, for example:
|
121
128
|
|
122
129
|
```js
|
123
|
-
|
124
|
-
|
130
|
+
import styles from 'ansi-styles';
|
131
|
+
|
132
|
+
styles.color.ansi(styles.rgbToAnsi(100, 200, 15)); // RGB to 16 color ansi foreground code
|
133
|
+
styles.bgColor.ansi(styles.hexToAnsi('#C0FFEE')); // HEX to 16 color ansi foreground code
|
134
|
+
|
135
|
+
styles.color.ansi256(styles.rgbToAnsi256(100, 200, 15)); // RGB to 256 color ansi foreground code
|
136
|
+
styles.bgColor.ansi256(styles.hexToAnsi256('#C0FFEE')); // HEX to 256 color ansi foreground code
|
125
137
|
|
126
|
-
|
127
|
-
|
138
|
+
styles.color.ansi16m(100, 200, 15); // RGB to 16 million color foreground code
|
139
|
+
styles.bgColor.ansi16m(...styles.hexToRgb('#C0FFEE')); // Hex (RGB) to 16 million color foreground code
|
128
140
|
```
|
129
141
|
|
130
142
|
## Related
|