UNPKG

1.01 kBTypeScriptView Raw
1import type {WriteStream} from 'node:tty';
2
3export 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/**
13Levels:
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*/
19export type ColorSupportLevel = 0 | 1 | 2 | 3;
20
21/**
22Detect whether the terminal supports color.
23*/
24export 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
46export type ColorInfo = ColorSupport | false;
47
48export function createSupportsColor(stream?: WriteStream, options?: Options): ColorInfo;
49
50declare const supportsColor: {
51 stdout: ColorInfo;
52 stderr: ColorInfo;
53};
54
55export default supportsColor;