UNPKG

5.2 kBTypeScriptView Raw
1export interface 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
13export 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
26export 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
75export 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
105export 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
135export 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;
181}
182
183/**
184Basic modifier names.
185*/
186export type ModifierName = keyof Modifier;
187
188/**
189Basic foreground color names.
190
191[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
192*/
193export type ForegroundColorName = keyof ForegroundColor;
194
195/**
196Basic background color names.
197
198[More colors here.](https://github.com/chalk/chalk/blob/main/readme.md#256-and-truecolor-color-support)
199*/
200export type BackgroundColorName = keyof BackgroundColor;
201
202/**
203Basic 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*/
207export type ColorName = ForegroundColorName | BackgroundColorName;
208
209/**
210Basic modifier names.
211*/
212export const modifierNames: readonly ModifierName[];
213
214/**
215Basic foreground color names.
216*/
217export const foregroundColorNames: readonly ForegroundColorName[];
218
219/**
220Basic background color names.
221*/
222export const backgroundColorNames: readonly BackgroundColorName[];
223
224/*
225Basic color names. The combination of foreground and background color names.
226*/
227export const colorNames: readonly ColorName[];
228
229declare const ansiStyles: {
230 readonly modifier: Modifier;
231 readonly color: ColorBase & ForegroundColor;
232 readonly bgColor: ColorBase & BackgroundColor;
233 readonly codes: ReadonlyMap<number, number>;
234} & ForegroundColor & BackgroundColor & Modifier & ConvertColor;
235
236export default ansiStyles;