@peteanderson/ansi 0.2.0 → 0.2.2

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.
Files changed (49) hide show
  1. package/README.md +9 -3
  2. package/dist/ansi.d.ts +6 -5
  3. package/dist/ansi.js +2 -0
  4. package/dist/index.d.ts +46 -174
  5. package/dist/sgr/color.d.ts +62 -0
  6. package/dist/sgr/color.js +111 -0
  7. package/dist/sgr/index.d.ts +59 -0
  8. package/dist/sgr/index.js +6 -0
  9. package/dist/sgr/reset.d.ts +1 -0
  10. package/dist/sgr/reset.js +3 -0
  11. package/dist/sgr/sgr.d.ts +14 -0
  12. package/dist/sgr/sgr.js +47 -0
  13. package/dist/sgr/style.d.ts +13 -0
  14. package/dist/sgr/style.js +16 -0
  15. package/dist/sgr/utils.d.ts +2 -0
  16. package/dist/sgr/utils.js +16 -0
  17. package/dist/simplify/atom.d.ts +3 -0
  18. package/dist/simplify/atom.js +28 -0
  19. package/dist/simplify/index.d.ts +2 -0
  20. package/dist/simplify/index.js +2 -0
  21. package/dist/simplify/lookup.d.ts +5 -0
  22. package/dist/simplify/lookup.js +77 -0
  23. package/dist/simplify/simplify.d.ts +1 -0
  24. package/dist/simplify/simplify.js +24 -0
  25. package/dist/simplify/state.d.ts +10 -0
  26. package/dist/simplify/state.js +57 -0
  27. package/dist/simplify/utils.d.ts +2 -0
  28. package/dist/simplify/utils.js +31 -0
  29. package/dist/strip.d.ts +1 -1
  30. package/dist/strip.js +2 -2
  31. package/package.json +1 -1
  32. package/src/ansi.js +2 -0
  33. package/src/sgr/color.js +130 -0
  34. package/src/sgr/index.js +5 -0
  35. package/src/sgr/reset.js +3 -0
  36. package/src/sgr/sgr.js +66 -0
  37. package/src/sgr/style.js +19 -0
  38. package/src/sgr/utils.js +20 -0
  39. package/src/simplify/atom.js +34 -0
  40. package/src/simplify/index.js +1 -0
  41. package/src/simplify/lookup.js +86 -0
  42. package/src/simplify/simplify.js +33 -0
  43. package/src/simplify/state.js +73 -0
  44. package/src/simplify/types.d.ts +28 -0
  45. package/src/simplify/utils.js +41 -0
  46. package/src/strip.js +2 -2
  47. package/dist/sgr.d.ts +0 -205
  48. package/dist/sgr.js +0 -89
  49. package/src/sgr.js +0 -113
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ const {buildExtendedColorAtom, buildIntensityAtom} = require("./atom");
4
+
5
+ /** @typedef {import("./types").Atom} Atom */
6
+ /** @typedef {import("./types").Attribute} Attribute */
7
+ /** @typedef {import("./types").AttributeMap} AttributeMap */
8
+ /** @typedef {import("./types").BuildAtom} BuildAtom */
9
+
10
+ /** @type {Record<number, [attribute: Attribute, buildAtom?: BuildAtom]>} */
11
+ const codeMap = {
12
+ 0 : ["reset"],
13
+ 1 : ["intensity", buildIntensityAtom],
14
+ 2 : ["intensity", buildIntensityAtom],
15
+ 3 : ["italic"],
16
+ 4 : ["underline"],
17
+ 7 : ["inverse"],
18
+ 8 : ["hidden"],
19
+ 9 : ["strikethrough"],
20
+ 21 : ["underline"],
21
+ 22 : ["intensity", buildIntensityAtom],
22
+ 23 : ["italic"],
23
+ 24 : ["underline"],
24
+ 27 : ["inverse"],
25
+ 28 : ["hidden"],
26
+ 29 : ["strikethrough"],
27
+ 30 : ["fg"],
28
+ 31 : ["fg"],
29
+ 32 : ["fg"],
30
+ 33 : ["fg"],
31
+ 34 : ["fg"],
32
+ 35 : ["fg"],
33
+ 36 : ["fg"],
34
+ 37 : ["fg"],
35
+ 38 : ["fg", buildExtendedColorAtom],
36
+ 39 : ["fg"],
37
+ 40 : ["bg"],
38
+ 41 : ["bg"],
39
+ 42 : ["bg"],
40
+ 43 : ["bg"],
41
+ 44 : ["bg"],
42
+ 45 : ["bg"],
43
+ 46 : ["bg"],
44
+ 47 : ["bg"],
45
+ 48 : ["bg", buildExtendedColorAtom],
46
+ 49 : ["bg"],
47
+ 51 : ["frame"],
48
+ 52 : ["frame"],
49
+ 53 : ["overline"],
50
+ 54 : ["frame"],
51
+ 55 : ["overline"],
52
+ 90 : ["fg"],
53
+ 91 : ["fg"],
54
+ 92 : ["fg"],
55
+ 93 : ["fg"],
56
+ 94 : ["fg"],
57
+ 95 : ["fg"],
58
+ 96 : ["fg"],
59
+ 97 : ["fg"],
60
+ 100 : ["bg"],
61
+ 101 : ["bg"],
62
+ 102 : ["bg"],
63
+ 103 : ["bg"],
64
+ 104 : ["bg"],
65
+ 105 : ["bg"],
66
+ 106 : ["bg"],
67
+ 107 : ["bg"],
68
+ };
69
+
70
+ /** @type {(codes: number[], index: number, state: AttributeMap) => Atom} */
71
+ function lookUpAtom(codes, index, state) {
72
+ const code = codes[index];
73
+ const entry = codeMap[code];
74
+
75
+ if (!entry)
76
+ return {attribute: code, code: [code]};
77
+
78
+ const [attribute, buildAtom] = entry;
79
+
80
+ if (buildAtom)
81
+ return buildAtom(attribute, codes, index, state);
82
+
83
+ return {attribute, code: [code]};
84
+ }
85
+
86
+ module.exports = {lookUpAtom};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ const {State} = require("./state");
4
+
5
+ const rxSGR = /\x1b\[([0-9;]+)m/;
6
+
7
+ /** @type {(text: string) => string} */
8
+ function simplify(text) {
9
+ const parts = text.split(rxSGR);
10
+
11
+ const state = new State();
12
+ let result = parts[0];
13
+
14
+ for (let i = 1; i < parts.length; ) {
15
+ let codes = parts[i++].split(";").map(Number);
16
+ let chunk = parts[i++];
17
+
18
+ while (!chunk && i < parts.length) {
19
+ // Merge consecutive SGR sequences.
20
+ codes.push(...parts[i++].split(";").map(Number));
21
+ chunk = parts[i++];
22
+ }
23
+
24
+ codes = state.update(codes);
25
+ if (codes.length)
26
+ result += `\x1b[${codes.join(";")}m`;
27
+ result += chunk;
28
+ }
29
+
30
+ return result;
31
+ }
32
+
33
+ module.exports = {simplify};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ const {lookUpAtom} = require("./lookup");
4
+ const {arraysEqual, transitionIntensity} = require("./utils");
5
+
6
+ /** @typedef {import("./types").Attribute} Attribute */
7
+ /** @typedef {import("./types").AttributeMap} AttributeMap */
8
+
9
+ /** @type {Map<Attribute, number[]>} */
10
+ const defaultCodes = new Map([
11
+ ["intensity", [22]],
12
+ ["italic", [23]],
13
+ ["underline", [24]],
14
+ ["inverse", [27]],
15
+ ["hidden", [28]],
16
+ ["strikethrough",[29]],
17
+ ["fg", [39]],
18
+ ["bg", [49]],
19
+ ["frame", [54]],
20
+ ["overline", [55]],
21
+ ]);
22
+
23
+ /** @type {AttributeMap} */
24
+ class State extends Map {
25
+ /** @type {(codes: number[]) => number[]} */
26
+ update(codes) {
27
+ /** @type {AttributeMap} */
28
+ let snapshot = new Map(this);
29
+
30
+ /** @type {Set<Attribute>} */
31
+ const attributes = new Set();
32
+
33
+ for (let i = 0; i < codes.length; i++) {
34
+ const {attribute, code, skip} = lookUpAtom(codes, i, this);
35
+
36
+ if (attribute === "reset") {
37
+ attributes.clear();
38
+ this.clear();
39
+ attributes.add("reset");
40
+ for (const [attr, defaultCode] of defaultCodes)
41
+ this.set(attr, defaultCode);
42
+
43
+ snapshot = new Map(this);
44
+ continue;
45
+ }
46
+
47
+ attributes.add(attribute);
48
+ this.set(attribute, code);
49
+
50
+ if (skip)
51
+ i += skip;
52
+ }
53
+
54
+ return Array.from(attributes).flatMap(attribute => {
55
+ if (attribute === "reset")
56
+ return [0];
57
+
58
+ const code = this.get(attribute);
59
+
60
+ if (arraysEqual(code, snapshot.get(attribute)))
61
+ return [];
62
+
63
+ if (attribute === "intensity") {
64
+ const previous = snapshot.get(attribute);
65
+ return transitionIntensity(previous, code);
66
+ }
67
+
68
+ return code;
69
+ });
70
+ }
71
+ }
72
+
73
+ module.exports = {State};
@@ -0,0 +1,28 @@
1
+ export type Attribute =
2
+ | "intensity"
3
+ | "italic"
4
+ | "underline"
5
+ | "inverse"
6
+ | "hidden"
7
+ | "strikethrough"
8
+ | "fg"
9
+ | "bg"
10
+ | "frame"
11
+ | "overline"
12
+ | "reset"
13
+ | number;
14
+
15
+ type AttributeMap = Map<Attribute, number[]>;
16
+
17
+ export interface Atom {
18
+ attribute : Attribute;
19
+ code : number[];
20
+ skip? : number;
21
+ }
22
+
23
+ export type BuildAtom = (
24
+ attribute: Attribute,
25
+ codes : number[],
26
+ index : number,
27
+ state : AttributeMap,
28
+ ) => Atom;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ /** @type {<T>(a: T[] | undefined, b: T[] | undefined) => boolean} */
4
+ function arraysEqual(a, b) {
5
+ if (a === b)
6
+ return true;
7
+
8
+ if (!a || !b || a.length !== b.length)
9
+ return false;
10
+
11
+ for (let i = 0; i < a.length; i++) {
12
+ if (a[i] !== b[i])
13
+ return false;
14
+ }
15
+
16
+ return true;
17
+ }
18
+
19
+ /** @type {(previous: number[] | undefined, current: number[]) => number[]} */
20
+ function transitionIntensity(previous, current) {
21
+ if (!previous || previous[0] === 22 || current[0] === 22)
22
+ return current;
23
+
24
+ const oldBold = previous[0] === 1;
25
+ const newBold = current[0] === 1;
26
+ const oldDim = previous[previous.length - 1] === 2;
27
+ const newDim = current[current.length - 1] === 2;
28
+
29
+ const result = [];
30
+
31
+ if (oldBold && !newBold || oldDim && !newDim)
32
+ result.push(22);
33
+ if (newBold && (!oldBold || result[0] === 22))
34
+ result.push(1);
35
+ if (newDim && (!oldDim || result[0] === 22))
36
+ result.push(2);
37
+
38
+ return result;
39
+ }
40
+
41
+ module.exports = {arraysEqual, transitionIntensity};
package/src/strip.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const {reset} = require("./sgr");
4
4
 
5
5
  const rxCSI = /\x1b\[[0-?]*[ -/]*[@-~]/g;
6
- const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR (m) codes.
6
+ const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR codes (m).
7
7
 
8
8
  /**
9
9
  * Remove all ANSI escape codes from the given text.
@@ -12,7 +12,7 @@ const rxUnsafe = /\x1b\[[0-?]*[ -/]*[@-ln-~]/g; // Everything except SGR (m) cod
12
12
  const strip = text => text.replace(rxCSI, '');
13
13
 
14
14
  /**
15
- * Remove all ANSI escape codes except SGR (m) codes, which are used for color and styling.
15
+ * Remove all ANSI escape codes except SGR codes (m), which are used for color and styling.
16
16
  * @type {(text: string) => string}
17
17
  */
18
18
  const sanitize = text => text.replace(rxUnsafe, '');
package/dist/sgr.d.ts DELETED
@@ -1,205 +0,0 @@
1
- export const reset: "\u001B[0m";
2
- export namespace style {
3
- let bold: ((s: string) => string) & {
4
- open: string;
5
- close: string;
6
- };
7
- let dim: ((s: string) => string) & {
8
- open: string;
9
- close: string;
10
- };
11
- let italic: ((s: string) => string) & {
12
- open: string;
13
- close: string;
14
- };
15
- let underline: ((s: string) => string) & {
16
- open: string;
17
- close: string;
18
- };
19
- let inverse: ((s: string) => string) & {
20
- open: string;
21
- close: string;
22
- };
23
- let hidden: ((s: string) => string) & {
24
- open: string;
25
- close: string;
26
- };
27
- let strikethrough: ((s: string) => string) & {
28
- open: string;
29
- close: string;
30
- };
31
- let doubleUnderline: ((s: string) => string) & {
32
- open: string;
33
- close: string;
34
- };
35
- let frame: ((s: string) => string) & {
36
- open: string;
37
- close: string;
38
- };
39
- let encircle: ((s: string) => string) & {
40
- open: string;
41
- close: string;
42
- };
43
- let overline: ((s: string) => string) & {
44
- open: string;
45
- close: string;
46
- };
47
- }
48
- export namespace fg {
49
- export let black: ((s: string) => string) & {
50
- open: string;
51
- close: string;
52
- };
53
- export let red: ((s: string) => string) & {
54
- open: string;
55
- close: string;
56
- };
57
- export let green: ((s: string) => string) & {
58
- open: string;
59
- close: string;
60
- };
61
- export let yellow: ((s: string) => string) & {
62
- open: string;
63
- close: string;
64
- };
65
- export let blue: ((s: string) => string) & {
66
- open: string;
67
- close: string;
68
- };
69
- export let magenta: ((s: string) => string) & {
70
- open: string;
71
- close: string;
72
- };
73
- export let cyan: ((s: string) => string) & {
74
- open: string;
75
- close: string;
76
- };
77
- export let white: ((s: string) => string) & {
78
- open: string;
79
- close: string;
80
- };
81
- export let brightBlack: ((s: string) => string) & {
82
- open: string;
83
- close: string;
84
- };
85
- export let brightRed: ((s: string) => string) & {
86
- open: string;
87
- close: string;
88
- };
89
- export let brightGreen: ((s: string) => string) & {
90
- open: string;
91
- close: string;
92
- };
93
- export let brightYellow: ((s: string) => string) & {
94
- open: string;
95
- close: string;
96
- };
97
- export let brightBlue: ((s: string) => string) & {
98
- open: string;
99
- close: string;
100
- };
101
- export let brightMagenta: ((s: string) => string) & {
102
- open: string;
103
- close: string;
104
- };
105
- export let brightCyan: ((s: string) => string) & {
106
- open: string;
107
- close: string;
108
- };
109
- export let brightWhite: ((s: string) => string) & {
110
- open: string;
111
- close: string;
112
- };
113
- let _default: string;
114
- export { _default as default };
115
- export let rgb: (r: number, g: number, b: number) => (text: string) => string;
116
- export let x256: (r: number, g: number, b: number) => (text: string) => string;
117
- }
118
- export namespace bg {
119
- let black_1: ((s: string) => string) & {
120
- open: string;
121
- close: string;
122
- };
123
- export { black_1 as black };
124
- let red_1: ((s: string) => string) & {
125
- open: string;
126
- close: string;
127
- };
128
- export { red_1 as red };
129
- let green_1: ((s: string) => string) & {
130
- open: string;
131
- close: string;
132
- };
133
- export { green_1 as green };
134
- let yellow_1: ((s: string) => string) & {
135
- open: string;
136
- close: string;
137
- };
138
- export { yellow_1 as yellow };
139
- let blue_1: ((s: string) => string) & {
140
- open: string;
141
- close: string;
142
- };
143
- export { blue_1 as blue };
144
- let magenta_1: ((s: string) => string) & {
145
- open: string;
146
- close: string;
147
- };
148
- export { magenta_1 as magenta };
149
- let cyan_1: ((s: string) => string) & {
150
- open: string;
151
- close: string;
152
- };
153
- export { cyan_1 as cyan };
154
- let white_1: ((s: string) => string) & {
155
- open: string;
156
- close: string;
157
- };
158
- export { white_1 as white };
159
- let brightBlack_1: ((s: string) => string) & {
160
- open: string;
161
- close: string;
162
- };
163
- export { brightBlack_1 as brightBlack };
164
- let brightRed_1: ((s: string) => string) & {
165
- open: string;
166
- close: string;
167
- };
168
- export { brightRed_1 as brightRed };
169
- let brightGreen_1: ((s: string) => string) & {
170
- open: string;
171
- close: string;
172
- };
173
- export { brightGreen_1 as brightGreen };
174
- let brightYellow_1: ((s: string) => string) & {
175
- open: string;
176
- close: string;
177
- };
178
- export { brightYellow_1 as brightYellow };
179
- let brightBlue_1: ((s: string) => string) & {
180
- open: string;
181
- close: string;
182
- };
183
- export { brightBlue_1 as brightBlue };
184
- let brightMagenta_1: ((s: string) => string) & {
185
- open: string;
186
- close: string;
187
- };
188
- export { brightMagenta_1 as brightMagenta };
189
- let brightCyan_1: ((s: string) => string) & {
190
- open: string;
191
- close: string;
192
- };
193
- export { brightCyan_1 as brightCyan };
194
- let brightWhite_1: ((s: string) => string) & {
195
- open: string;
196
- close: string;
197
- };
198
- export { brightWhite_1 as brightWhite };
199
- let _default_1: string;
200
- export { _default_1 as default };
201
- let rgb_1: (r: number, g: number, b: number) => (text: string) => string;
202
- export { rgb_1 as rgb };
203
- let x256_1: (r: number, g: number, b: number) => (text: string) => string;
204
- export { x256_1 as x256 };
205
- }
package/dist/sgr.js DELETED
@@ -1,89 +0,0 @@
1
- "use strict";
2
- /**
3
- * @param {number | string} open
4
- * @param {number | string} close
5
- */
6
- function sgr(open, close) {
7
- const openSequence = `\x1b[${open}m`;
8
- const closeSequence = `\x1b[${close}m`;
9
- return Object.assign(
10
- /** @type {(text: string) => string} */
11
- s => openSequence +
12
- s.replaceAll(openSequence, '').replaceAll(closeSequence, openSequence) +
13
- closeSequence, { open: openSequence, close: closeSequence });
14
- }
15
- /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
16
- const rgb = (r, g, b, open, close) => sgr(`${open};2;${r};${g};${b}`, close);
17
- /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
18
- function x256(r, g, b, open, close) {
19
- if (r === g && g === b) {
20
- // grayscale
21
- return sgr(`${open};5;${232 + Math.floor(r * 24 / 256)}`, close);
22
- }
23
- // 6x6x6 color cube
24
- return sgr(`${open};5;${16 +
25
- Math.floor(r * 6 / 256) * 36 +
26
- Math.floor(g * 6 / 256) * 6 +
27
- Math.floor(b * 6 / 256)}`, close);
28
- }
29
- const reset = "\x1b[0m";
30
- const style = {
31
- bold: sgr(1, 22),
32
- dim: sgr(2, 22),
33
- italic: sgr(3, 23),
34
- underline: sgr(4, 24),
35
- inverse: sgr(7, 27),
36
- hidden: sgr(8, 28),
37
- strikethrough: sgr(9, 29),
38
- doubleUnderline: sgr(21, 24),
39
- frame: sgr(51, 54),
40
- encircle: sgr(52, 54),
41
- overline: sgr(53, 55),
42
- };
43
- const fg = {
44
- black: sgr(30, 39),
45
- red: sgr(31, 39),
46
- green: sgr(32, 39),
47
- yellow: sgr(33, 39),
48
- blue: sgr(34, 39),
49
- magenta: sgr(35, 39),
50
- cyan: sgr(36, 39),
51
- white: sgr(37, 39),
52
- brightBlack: sgr(90, 39),
53
- brightRed: sgr(91, 39),
54
- brightGreen: sgr(92, 39),
55
- brightYellow: sgr(93, 39),
56
- brightBlue: sgr(94, 39),
57
- brightMagenta: sgr(95, 39),
58
- brightCyan: sgr(96, 39),
59
- brightWhite: sgr(97, 39),
60
- default: "\x1b[39m",
61
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
62
- rgb: (r, g, b) => rgb(r, g, b, 38, 39),
63
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
64
- x256: (r, g, b) => x256(r, g, b, 38, 39),
65
- };
66
- const bg = {
67
- black: sgr(40, 49),
68
- red: sgr(41, 49),
69
- green: sgr(42, 49),
70
- yellow: sgr(43, 49),
71
- blue: sgr(44, 49),
72
- magenta: sgr(45, 49),
73
- cyan: sgr(46, 49),
74
- white: sgr(47, 49),
75
- brightBlack: sgr(100, 49),
76
- brightRed: sgr(101, 49),
77
- brightGreen: sgr(102, 49),
78
- brightYellow: sgr(103, 49),
79
- brightBlue: sgr(104, 49),
80
- brightMagenta: sgr(105, 49),
81
- brightCyan: sgr(106, 49),
82
- brightWhite: sgr(107, 49),
83
- default: "\x1b[49m",
84
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
85
- rgb: (r, g, b) => rgb(r, g, b, 48, 49),
86
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
87
- x256: (r, g, b) => x256(r, g, b, 48, 49),
88
- };
89
- module.exports = { reset, style, fg, bg };
package/src/sgr.js DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * @param {number | string} open
5
- * @param {number | string} close
6
- */
7
- function sgr(open, close) {
8
- const openSequence = `\x1b[${open}m`;
9
- const closeSequence = `\x1b[${close}m`;
10
-
11
- return Object.assign(
12
- /** @type {(text: string) => string} */
13
- s =>
14
- openSequence +
15
- s.replaceAll(openSequence, '').replaceAll(closeSequence, openSequence) +
16
- closeSequence,
17
- {open: openSequence, close: closeSequence}
18
- );
19
- }
20
-
21
- /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
22
- const rgb = (r, g, b, open, close) => sgr(`${open};2;${r};${g};${b}`, close);
23
-
24
- /** @type {(r: number, g: number, b: number, open: number, close: number) => (text: string) => string} */
25
- function x256(r, g, b, open, close) {
26
- if (r === g && g === b) {
27
- // grayscale
28
- return sgr(`${open};5;${232 + Math.floor(r * 24 / 256)}`, close);
29
- }
30
-
31
- // 6x6x6 color cube
32
- return sgr(
33
- `${open};5;${
34
- 16 +
35
- Math.floor(r * 6 / 256) * 36 +
36
- Math.floor(g * 6 / 256) * 6 +
37
- Math.floor(b * 6 / 256)
38
- }`,
39
- close,
40
- );
41
- }
42
-
43
- const reset = "\x1b[0m";
44
-
45
- const style = {
46
- bold : sgr(1, 22),
47
- dim : sgr(2, 22),
48
- italic : sgr(3, 23),
49
- underline : sgr(4, 24),
50
- inverse : sgr(7, 27),
51
- hidden : sgr(8, 28),
52
- strikethrough : sgr(9, 29),
53
- doubleUnderline : sgr(21, 24),
54
- frame : sgr(51, 54),
55
- encircle : sgr(52, 54),
56
- overline : sgr(53, 55),
57
- };
58
-
59
- const fg = {
60
- black : sgr(30, 39),
61
- red : sgr(31, 39),
62
- green : sgr(32, 39),
63
- yellow : sgr(33, 39),
64
- blue : sgr(34, 39),
65
- magenta : sgr(35, 39),
66
- cyan : sgr(36, 39),
67
- white : sgr(37, 39),
68
-
69
- brightBlack : sgr(90, 39),
70
- brightRed : sgr(91, 39),
71
- brightGreen : sgr(92, 39),
72
- brightYellow : sgr(93, 39),
73
- brightBlue : sgr(94, 39),
74
- brightMagenta : sgr(95, 39),
75
- brightCyan : sgr(96, 39),
76
- brightWhite : sgr(97, 39),
77
-
78
- default : "\x1b[39m",
79
-
80
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
81
- rgb : (r, g, b) => rgb(r, g, b, 38, 39),
82
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
83
- x256 : (r, g, b) => x256(r, g, b, 38, 39),
84
- };
85
-
86
- const bg = {
87
- black : sgr(40, 49),
88
- red : sgr(41, 49),
89
- green : sgr(42, 49),
90
- yellow : sgr(43, 49),
91
- blue : sgr(44, 49),
92
- magenta : sgr(45, 49),
93
- cyan : sgr(46, 49),
94
- white : sgr(47, 49),
95
-
96
- brightBlack : sgr(100, 49),
97
- brightRed : sgr(101, 49),
98
- brightGreen : sgr(102, 49),
99
- brightYellow : sgr(103, 49),
100
- brightBlue : sgr(104, 49),
101
- brightMagenta : sgr(105, 49),
102
- brightCyan : sgr(106, 49),
103
- brightWhite : sgr(107, 49),
104
-
105
- default : "\x1b[49m",
106
-
107
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
108
- rgb : (r, g, b) => rgb(r, g, b, 48, 49),
109
- /** @type {(r: number, g: number, b: number) => (text: string) => string} */
110
- x256 : (r, g, b) => x256(r, g, b, 48, 49),
111
- };
112
-
113
- module.exports = {reset, style, fg, bg};