console-toolkit 1.2.8 → 1.2.10
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 +70 -25
- package/package.json +26 -6
- package/src/alphanumeric/arrows.d.ts +48 -0
- package/src/alphanumeric/arrows.js +23 -0
- package/src/alphanumeric/fractions.d.ts +65 -0
- package/src/alphanumeric/fractions.js +49 -0
- package/src/alphanumeric/number-formatters.d.ts +91 -0
- package/src/alphanumeric/number-formatters.js +45 -1
- package/src/alphanumeric/roman.d.ts +15 -0
- package/src/alphanumeric/roman.js +12 -0
- package/src/alphanumeric/unicode-cultural-numbers.d.ts +65 -0
- package/src/alphanumeric/unicode-cultural-numbers.js +1 -0
- package/src/alphanumeric/unicode-letters.d.ts +32 -0
- package/src/alphanumeric/unicode-letters.js +8 -0
- package/src/alphanumeric/unicode-numbers.d.ts +44 -0
- package/src/alphanumeric/unicode-numbers.js +21 -0
- package/src/alphanumeric/utils.d.ts +45 -0
- package/src/alphanumeric/utils.js +26 -0
- package/src/ansi/csi.d.ts +141 -0
- package/src/ansi/csi.js +51 -2
- package/src/ansi/index.d.ts +26 -0
- package/src/ansi/sgr-constants.d.ts +173 -0
- package/src/ansi/sgr-state.d.ts +91 -0
- package/src/ansi/sgr-state.js +45 -0
- package/src/ansi/sgr.d.ts +587 -0
- package/src/ansi/sgr.js +426 -6
- package/src/box.d.ts +160 -0
- package/src/box.js +113 -12
- package/src/charts/bars/block-frac-grouped.d.ts +12 -0
- package/src/charts/bars/block-frac-grouped.js +6 -0
- package/src/charts/bars/block-frac.d.ts +34 -0
- package/src/charts/bars/block-frac.js +13 -0
- package/src/charts/bars/block-grouped.d.ts +12 -0
- package/src/charts/bars/block-grouped.js +6 -0
- package/src/charts/bars/block.d.ts +43 -0
- package/src/charts/bars/block.js +13 -0
- package/src/charts/bars/draw-grouped.d.ts +41 -0
- package/src/charts/bars/draw-grouped.js +4 -0
- package/src/charts/bars/draw-stacked.d.ts +47 -0
- package/src/charts/bars/draw-stacked.js +4 -0
- package/src/charts/bars/frac-grouped.d.ts +32 -0
- package/src/charts/bars/frac-grouped.js +13 -0
- package/src/charts/bars/plain-grouped.d.ts +12 -0
- package/src/charts/bars/plain-grouped.js +6 -0
- package/src/charts/bars/plain.d.ts +75 -0
- package/src/charts/bars/plain.js +27 -0
- package/src/charts/columns/block-frac-grouped.d.ts +12 -0
- package/src/charts/columns/block-frac-grouped.js +6 -0
- package/src/charts/columns/block-frac.d.ts +39 -0
- package/src/charts/columns/block-frac.js +13 -0
- package/src/charts/columns/block-grouped.d.ts +12 -0
- package/src/charts/columns/block-grouped.js +6 -0
- package/src/charts/columns/block.d.ts +43 -0
- package/src/charts/columns/block.js +13 -0
- package/src/charts/columns/draw-grouped.d.ts +41 -0
- package/src/charts/columns/draw-grouped.js +4 -0
- package/src/charts/columns/draw-stacked.d.ts +39 -0
- package/src/charts/columns/draw-stacked.js +4 -0
- package/src/charts/columns/frac-grouped.d.ts +37 -0
- package/src/charts/columns/frac-grouped.js +13 -0
- package/src/charts/columns/plain-grouped.d.ts +12 -0
- package/src/charts/columns/plain-grouped.js +6 -0
- package/src/charts/columns/plain.d.ts +32 -0
- package/src/charts/columns/plain.js +13 -0
- package/src/charts/themes/default.d.ts +6 -0
- package/src/charts/themes/default.js +1 -0
- package/src/charts/themes/rainbow-reversed.d.ts +6 -0
- package/src/charts/themes/rainbow-reversed.js +2 -1
- package/src/charts/themes/rainbow.d.ts +6 -0
- package/src/charts/themes/rainbow.js +1 -0
- package/src/charts/utils.d.ts +79 -0
- package/src/charts/utils.js +32 -4
- package/src/draw-block-frac.d.ts +16 -0
- package/src/draw-block-frac.js +14 -0
- package/src/draw-block.d.ts +53 -0
- package/src/draw-block.js +25 -1
- package/src/meta.d.ts +84 -0
- package/src/meta.js +64 -0
- package/src/output/show.d.ts +55 -0
- package/src/output/show.js +28 -0
- package/src/output/updater.d.ts +114 -0
- package/src/output/updater.js +58 -4
- package/src/output/writer.d.ts +87 -0
- package/src/output/writer.js +57 -5
- package/src/panel.d.ts +402 -0
- package/src/panel.js +219 -5
- package/src/plot/bitmap.d.ts +80 -0
- package/src/plot/bitmap.js +33 -4
- package/src/plot/draw-line.d.ts +13 -0
- package/src/plot/draw-line.js +8 -0
- package/src/plot/draw-rect.d.ts +13 -0
- package/src/plot/draw-rect.js +38 -30
- package/src/plot/index.d.ts +39 -0
- package/src/plot/index.js +22 -0
- package/src/plot/to-quads.d.ts +10 -0
- package/src/plot/to-quads.js +5 -0
- package/src/spinner/index.d.ts +4 -0
- package/src/spinner/index.js +0 -2
- package/src/spinner/spin.d.ts +13 -0
- package/src/spinner/spin.js +13 -2
- package/src/spinner/spinner.d.ts +69 -0
- package/src/spinner/spinner.js +30 -2
- package/src/spinner/spinners.d.ts +34 -0
- package/src/spinner/spinners.js +23 -9
- package/src/strings/clip.d.ts +21 -0
- package/src/strings/clip.js +10 -0
- package/src/strings/parse.d.ts +23 -0
- package/src/strings/parse.js +7 -0
- package/src/strings/split.d.ts +38 -0
- package/src/strings/split.js +15 -0
- package/src/strings.d.ts +44 -0
- package/src/strings.js +34 -4
- package/src/style.d.ts +462 -0
- package/src/style.js +58 -4
- package/src/symbols.d.ts +167 -0
- package/src/symbols.js +91 -7
- package/src/table/draw-borders.d.ts +38 -0
- package/src/table/draw-borders.js +10 -2
- package/src/table/index.d.ts +8 -0
- package/src/table/index.js +1 -0
- package/src/table/table.d.ts +234 -0
- package/src/table/table.js +59 -1
- package/src/themes/blocks/unicode-half.d.ts +6 -0
- package/src/themes/blocks/unicode-half.js +1 -0
- package/src/themes/blocks/unicode-thin.d.ts +6 -0
- package/src/themes/blocks/unicode-thin.js +1 -0
- package/src/themes/lines/ascii-compact.d.ts +6 -0
- package/src/themes/lines/ascii-compact.js +1 -0
- package/src/themes/lines/ascii-dots.d.ts +6 -0
- package/src/themes/lines/ascii-dots.js +1 -0
- package/src/themes/lines/ascii-girder.d.ts +6 -0
- package/src/themes/lines/ascii-girder.js +1 -0
- package/src/themes/lines/ascii-github.d.ts +6 -0
- package/src/themes/lines/ascii-github.js +1 -0
- package/src/themes/lines/ascii-reddit.d.ts +6 -0
- package/src/themes/lines/ascii-reddit.js +1 -0
- package/src/themes/lines/ascii-rounded.d.ts +6 -0
- package/src/themes/lines/ascii-rounded.js +1 -0
- package/src/themes/lines/ascii.d.ts +6 -0
- package/src/themes/lines/ascii.js +1 -0
- package/src/themes/lines/unicode-bold.d.ts +6 -0
- package/src/themes/lines/unicode-bold.js +1 -0
- package/src/themes/lines/unicode-rounded.d.ts +6 -0
- package/src/themes/lines/unicode-rounded.js +1 -0
- package/src/themes/lines/unicode.d.ts +6 -0
- package/src/themes/lines/unicode.js +1 -0
- package/src/themes/utils.d.ts +33 -0
- package/src/themes/utils.js +7 -0
- package/src/turtle/draw-line-art.d.ts +19 -0
- package/src/turtle/draw-line-art.js +7 -0
- package/src/turtle/draw-unicode.d.ts +19 -0
- package/src/turtle/draw-unicode.js +8 -0
- package/src/turtle/index.d.ts +21 -0
- package/src/turtle/index.js +8 -0
- package/src/turtle/turtle.d.ts +269 -0
- package/src/turtle/turtle.js +124 -4
package/src/ansi/sgr.js
CHANGED
|
@@ -5,10 +5,17 @@
|
|
|
5
5
|
// See https://en.wikipedia.org/wiki/ANSI_escape_code for more details.
|
|
6
6
|
|
|
7
7
|
// matcher
|
|
8
|
+
/** RegExp matching SGR (Select Graphics Rendition) escape sequences.
|
|
9
|
+
* @type {RegExp}
|
|
10
|
+
*/
|
|
8
11
|
export const matchSgr = /\x1B\[([\x30-\x3F]*)([\x20-\x2F]*)m/g;
|
|
9
12
|
|
|
13
|
+
/** Standard color name-to-number mapping.
|
|
14
|
+
* @type {{BLACK: 0, RED: 1, GREEN: 2, YELLOW: 3, BLUE: 4, MAGENTA: 5, CYAN: 6, WHITE: 7, DEFAULT: 9}}
|
|
15
|
+
*/
|
|
10
16
|
export const Colors = {BLACK: 0, RED: 1, GREEN: 2, YELLOW: 3, BLUE: 4, MAGENTA: 5, CYAN: 6, WHITE: 7, DEFAULT: 9};
|
|
11
17
|
|
|
18
|
+
/** SGR command code constants (e.g., BOLD='1', UNDERLINE='4'). */
|
|
12
19
|
export const Commands = {
|
|
13
20
|
RESET_ALL: '0',
|
|
14
21
|
BOLD: '1',
|
|
@@ -49,21 +56,36 @@ export const Commands = {
|
|
|
49
56
|
RESET_DECORATION_COLOR: '59'
|
|
50
57
|
};
|
|
51
58
|
|
|
59
|
+
/** Color format identifiers for extended colors.
|
|
60
|
+
* @type {{COLOR_256: string, TRUE_COLOR: string}}
|
|
61
|
+
*/
|
|
52
62
|
export const ColorFormat = {COLOR_256: '5', TRUE_COLOR: '2'};
|
|
63
|
+
/** Maps color format identifiers to their parameter count.
|
|
64
|
+
* @type {Record<string, number>}
|
|
65
|
+
*/
|
|
53
66
|
export const ColorFormatSize = {[ColorFormat.COLOR_256]: 3, [ColorFormat.TRUE_COLOR]: 5};
|
|
54
67
|
|
|
68
|
+
/** Foreground color configuration.
|
|
69
|
+
* @type {import('./sgr.js').ColorOptions}
|
|
70
|
+
*/
|
|
55
71
|
export const FgColorOptions = {
|
|
56
72
|
base: 30,
|
|
57
73
|
brightBase: 90,
|
|
58
74
|
default: Commands.DEFAULT_COLOR,
|
|
59
75
|
extended: Commands.EXTENDED_COLOR
|
|
60
76
|
};
|
|
77
|
+
/** Background color configuration.
|
|
78
|
+
* @type {import('./sgr.js').ColorOptions}
|
|
79
|
+
*/
|
|
61
80
|
export const BgColorOptions = {
|
|
62
81
|
base: 40,
|
|
63
82
|
brightBase: 100,
|
|
64
83
|
default: Commands.BG_DEFAULT_COLOR,
|
|
65
84
|
extended: Commands.BG_EXTENDED_COLOR
|
|
66
85
|
};
|
|
86
|
+
/** Decoration (underline) color configuration.
|
|
87
|
+
* @type {import('./sgr.js').ColorOptions}
|
|
88
|
+
*/
|
|
67
89
|
export const DecorationColorOptions = {
|
|
68
90
|
base: 0,
|
|
69
91
|
brightBase: 100,
|
|
@@ -79,11 +101,27 @@ for (const [k, v] of Object.entries(Commands)) {
|
|
|
79
101
|
resetCommands[Commands[cmd]] = v;
|
|
80
102
|
}
|
|
81
103
|
|
|
104
|
+
/** Checks if a command is a foreground color command.
|
|
105
|
+
* @param {string} command
|
|
106
|
+
* @returns {boolean}
|
|
107
|
+
*/
|
|
82
108
|
export const isFgColorCommand = command => (command >= '30' && command <= '37') || (command >= '90' && command <= '97');
|
|
109
|
+
/** Checks if a command is a background color command.
|
|
110
|
+
* @param {string} command
|
|
111
|
+
* @returns {boolean}
|
|
112
|
+
*/
|
|
83
113
|
export const isBgColorCommand = command =>
|
|
84
114
|
(command >= '40' && command <= '47') || (command >= '100' && command <= '107');
|
|
115
|
+
/** Checks if a command is a font command.
|
|
116
|
+
* @param {string} command
|
|
117
|
+
* @returns {boolean}
|
|
118
|
+
*/
|
|
85
119
|
export const isFontCommand = command => command >= '10' && command <= '20';
|
|
86
120
|
|
|
121
|
+
/** Returns the reset command for a given SGR command.
|
|
122
|
+
* @param {string} command - The SGR command string or name.
|
|
123
|
+
* @returns {string|undefined} The reset command, or undefined if not found.
|
|
124
|
+
*/
|
|
87
125
|
export const reset = command => {
|
|
88
126
|
command = String(command).toUpperCase();
|
|
89
127
|
if (Commands.hasOwnProperty(command)) {
|
|
@@ -96,8 +134,16 @@ export const reset = command => {
|
|
|
96
134
|
// return undefined in all other cases
|
|
97
135
|
};
|
|
98
136
|
|
|
137
|
+
/** Creates an SGR escape sequence from one or more commands.
|
|
138
|
+
* @param {string|string[]|number[]} commands - Command(s) to encode.
|
|
139
|
+
* @returns {string} The SGR escape sequence.
|
|
140
|
+
*/
|
|
99
141
|
export const setCommands = commands => `\x1B[${Array.isArray(commands) ? commands.join(';') : commands}m`;
|
|
100
142
|
|
|
143
|
+
/** Converts a color name or number to a standard color number (0-9).
|
|
144
|
+
* @param {string|number} color - Color name or number.
|
|
145
|
+
* @returns {number} The color number.
|
|
146
|
+
*/
|
|
101
147
|
export const colorNumber = color => {
|
|
102
148
|
if (typeof color == 'string') {
|
|
103
149
|
if (/^\d+$/.test(color)) {
|
|
@@ -109,30 +155,128 @@ export const colorNumber = color => {
|
|
|
109
155
|
}
|
|
110
156
|
return typeof color == 'number' && color >= 0 && color <= 9 ? color : 0;
|
|
111
157
|
};
|
|
158
|
+
/** Converts RGB values to a standard color number.
|
|
159
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
160
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
161
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
162
|
+
* @returns {number} a color number from 0 to 7
|
|
163
|
+
*/
|
|
112
164
|
export const colorStdRgb = (r, g, b) => (r ? 1 : 0) + (g ? 2 : 0) + (b ? 4 : 0);
|
|
113
165
|
|
|
166
|
+
/** Returns the foreground color SGR code.
|
|
167
|
+
* @param {string|number} color - Color name or number.
|
|
168
|
+
* @returns {number}
|
|
169
|
+
*/
|
|
114
170
|
export const getColor = color => 30 + colorNumber(color);
|
|
171
|
+
/** Returns the background color SGR code.
|
|
172
|
+
* @param {string|number} color - Color name or number.
|
|
173
|
+
* @returns {number}
|
|
174
|
+
*/
|
|
115
175
|
export const getBgColor = color => 40 + colorNumber(color);
|
|
176
|
+
/** Returns the bright foreground color SGR code.
|
|
177
|
+
* @param {string|number} color - Color name or number.
|
|
178
|
+
* @returns {number}
|
|
179
|
+
*/
|
|
116
180
|
export const getBrightColor = color => 90 + colorNumber(color);
|
|
181
|
+
/** Returns the bright background color SGR code.
|
|
182
|
+
* @param {string|number} color - Color name or number.
|
|
183
|
+
* @returns {number}
|
|
184
|
+
*/
|
|
117
185
|
export const getBgBrightColor = color => 100 + colorNumber(color);
|
|
186
|
+
/** Returns the foreground standard RGB color SGR code.
|
|
187
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
188
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
189
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
190
|
+
* @returns {number}
|
|
191
|
+
*/
|
|
118
192
|
export const getStdRgb = (r, g, b) => getColor(colorStdRgb(r, g, b));
|
|
193
|
+
/** Returns the background standard RGB color SGR code.
|
|
194
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
195
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
196
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
197
|
+
* @returns {number}
|
|
198
|
+
*/
|
|
119
199
|
export const getBgStdRgb = (r, g, b) => getBgColor(colorStdRgb(r, g, b));
|
|
200
|
+
/** Returns the bright foreground standard RGB color SGR code.
|
|
201
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
202
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
203
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
204
|
+
* @returns {number}
|
|
205
|
+
*/
|
|
120
206
|
export const getBrightStdRgb = (r, g, b) => getBrightColor(colorStdRgb(r, g, b));
|
|
207
|
+
/** Returns the bright background standard RGB color SGR code.
|
|
208
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
209
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
210
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
211
|
+
* @returns {number}
|
|
212
|
+
*/
|
|
121
213
|
export const getBgBrightStdRgb = (r, g, b) => getBgBrightColor(colorStdRgb(r, g, b));
|
|
122
214
|
|
|
215
|
+
/** Sets the foreground color.
|
|
216
|
+
* @param {string|number} color - Color name or number.
|
|
217
|
+
* @returns {string} SGR escape sequence.
|
|
218
|
+
*/
|
|
123
219
|
export const setColor = color => setCommands(getColor(color));
|
|
220
|
+
/** Sets the background color.
|
|
221
|
+
* @param {string|number} color - Color name or number.
|
|
222
|
+
* @returns {string} SGR escape sequence.
|
|
223
|
+
*/
|
|
124
224
|
export const setBgColor = color => setCommands(getBgColor(color));
|
|
225
|
+
/** Sets the bright foreground color.
|
|
226
|
+
* @param {string|number} color - Color name or number.
|
|
227
|
+
* @returns {string} SGR escape sequence.
|
|
228
|
+
*/
|
|
125
229
|
export const setBrightColor = color => setCommands(getBrightColor(color));
|
|
230
|
+
/** Sets the bright background color.
|
|
231
|
+
* @param {string|number} color - Color name or number.
|
|
232
|
+
* @returns {string} SGR escape sequence.
|
|
233
|
+
*/
|
|
126
234
|
export const setBgBrightColor = color => setCommands(getBgBrightColor(color));
|
|
235
|
+
/** Sets the foreground standard RGB color.
|
|
236
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
237
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
238
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
239
|
+
* @returns {string} SGR escape sequence.
|
|
240
|
+
*/
|
|
127
241
|
export const setStdRgb = (r, g, b) => setCommands(getStdRgb(r, g, b));
|
|
242
|
+
/** Sets the background standard RGB color.
|
|
243
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
244
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
245
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
246
|
+
* @returns {string} SGR escape sequence.
|
|
247
|
+
*/
|
|
128
248
|
export const setBgStdRgb = (r, g, b) => setCommands(getBgStdRgb(r, g, b));
|
|
249
|
+
/** Sets the bright foreground standard RGB color.
|
|
250
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
251
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
252
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
253
|
+
* @returns {string} SGR escape sequence.
|
|
254
|
+
*/
|
|
129
255
|
export const setBrightStdRgb = (r, g, b) => setCommands(getBrightStdRgb(r, g, b));
|
|
256
|
+
/** Sets the bright background standard RGB color.
|
|
257
|
+
* @param {number|boolean} r - Red component (truthy/falsy).
|
|
258
|
+
* @param {number|boolean} g - Green component (truthy/falsy).
|
|
259
|
+
* @param {number|boolean} b - Blue component (truthy/falsy).
|
|
260
|
+
* @returns {string} SGR escape sequence.
|
|
261
|
+
*/
|
|
130
262
|
export const setBgBrightStdRgb = (r, g, b) => setCommands(getBgBrightStdRgb(r, g, b));
|
|
131
263
|
|
|
264
|
+
/** Converts a font number to a valid font index.
|
|
265
|
+
* @param {number} font - Font number.
|
|
266
|
+
* @returns {number} The font index.
|
|
267
|
+
*/
|
|
132
268
|
export const fontNumber = font => (typeof font == 'number' && font >= 0 && font <= 10 ? font : 0);
|
|
133
269
|
|
|
270
|
+
/** Returns the SGR code for a font.
|
|
271
|
+
* @param {number} font - Font number.
|
|
272
|
+
* @returns {number}
|
|
273
|
+
*/
|
|
134
274
|
export const getFont = font => 10 + fontNumber(font);
|
|
135
|
-
|
|
275
|
+
/** Sets the font.
|
|
276
|
+
* @param {number} font - Font number.
|
|
277
|
+
* @returns {string} SGR escape sequence.
|
|
278
|
+
*/
|
|
279
|
+
export const setFont = font => setCommands(getFont(font));
|
|
136
280
|
|
|
137
281
|
const oneSixth = 6.0 / 256;
|
|
138
282
|
const oneTwentyFourth = 24.0 / 256;
|
|
@@ -142,73 +286,349 @@ const lim = (from, to) => value => Math.max(from, Math.min(to, value)); // inclu
|
|
|
142
286
|
const lim5 = lim(0, 5);
|
|
143
287
|
const lim23 = lim(0, 23);
|
|
144
288
|
|
|
289
|
+
/** Returns foreground 256-color command array for a raw palette index.
|
|
290
|
+
* @param {number} color - Palette index (0-255).
|
|
291
|
+
* @returns {string[]}
|
|
292
|
+
*/
|
|
145
293
|
export const getRawColor256 = color => [Commands.EXTENDED_COLOR, ColorFormat.COLOR_256, color];
|
|
294
|
+
/** Returns foreground 256-color command array for a standard color.
|
|
295
|
+
* @param {string|number} color - Color name or number.
|
|
296
|
+
* @returns {string[]}
|
|
297
|
+
*/
|
|
146
298
|
export const getStdColor256 = color => getRawColor256(colorNumber(color));
|
|
299
|
+
/** Returns foreground 256-color command array for a bright standard color.
|
|
300
|
+
* @param {string|number} color - Color name or number.
|
|
301
|
+
* @returns {string[]}
|
|
302
|
+
*/
|
|
147
303
|
export const getBrightStdColor256 = color => getRawColor256(8 + colorNumber(color));
|
|
304
|
+
/** Returns foreground 256-color command array for a 6x6x6 RGB color.
|
|
305
|
+
* @param {number} r - Red component (0-5).
|
|
306
|
+
* @param {number} g - Green component (0-5).
|
|
307
|
+
* @param {number} b - Blue component (0-5).
|
|
308
|
+
* @returns {string[]}
|
|
309
|
+
*/
|
|
148
310
|
export const getColor6 = (r, g, b) => getRawColor256(16 + 36 * lim5(r) + 6 * lim5(g) + lim5(b));
|
|
311
|
+
/** Returns foreground 256-color command array for an RGB color.
|
|
312
|
+
* @param {number} r - Red (0-255).
|
|
313
|
+
* @param {number} g - Green (0-255).
|
|
314
|
+
* @param {number} b - Blue (0-255).
|
|
315
|
+
* @returns {string[]}
|
|
316
|
+
*/
|
|
149
317
|
export const getColor256 = (r, g, b) => getColor6(get6(r), get6(g), get6(b));
|
|
318
|
+
/** Returns foreground 256-color command array for a hex color.
|
|
319
|
+
* @param {number} hex - Hex color value (e.g., 0xFF0000).
|
|
320
|
+
* @returns {string[]}
|
|
321
|
+
*/
|
|
150
322
|
export const getHexColor256 = hex => getColor256((hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff);
|
|
323
|
+
/** Returns foreground 256-color command array for a 24-shade gray.
|
|
324
|
+
* @param {number} i - Gray index (0-23).
|
|
325
|
+
* @returns {string[]}
|
|
326
|
+
*/
|
|
151
327
|
export const getGrayColor24 = i => getRawColor256(232 + lim23(i));
|
|
328
|
+
/** Returns foreground 256-color command array for a gray by intensity.
|
|
329
|
+
* @param {number} i - Gray intensity (0-255).
|
|
330
|
+
* @returns {string[]}
|
|
331
|
+
*/
|
|
152
332
|
export const getGrayColor256 = i => getGrayColor24(get24(i));
|
|
153
333
|
|
|
334
|
+
/** Sets foreground 256-color by raw palette index.
|
|
335
|
+
* @param {number} color - Palette index (0-255).
|
|
336
|
+
* @returns {string} SGR escape sequence.
|
|
337
|
+
*/
|
|
154
338
|
export const setRawColor256 = color => setCommands(getRawColor256(color));
|
|
339
|
+
/** Sets foreground 256-color by standard color.
|
|
340
|
+
* @param {string|number} color - Color name or number.
|
|
341
|
+
* @returns {string} SGR escape sequence.
|
|
342
|
+
*/
|
|
155
343
|
export const setStdColor256 = color => setCommands(getStdColor256(color));
|
|
344
|
+
/** Sets foreground 256-color by bright standard color.
|
|
345
|
+
* @param {string|number} color - Color name or number.
|
|
346
|
+
* @returns {string} SGR escape sequence.
|
|
347
|
+
*/
|
|
156
348
|
export const setBrightStdColor256 = color => setCommands(getBrightStdColor256(color));
|
|
349
|
+
/** Sets foreground 256-color by 6x6x6 RGB.
|
|
350
|
+
* @param {number} r - Red (0-5).
|
|
351
|
+
* @param {number} g - Green (0-5).
|
|
352
|
+
* @param {number} b - Blue (0-5).
|
|
353
|
+
* @returns {string} SGR escape sequence.
|
|
354
|
+
*/
|
|
157
355
|
export const setColor6 = (r, g, b) => setCommands(getColor6(r, g, b));
|
|
356
|
+
/** Sets foreground 256-color by RGB.
|
|
357
|
+
* @param {number} r - Red (0-255).
|
|
358
|
+
* @param {number} g - Green (0-255).
|
|
359
|
+
* @param {number} b - Blue (0-255).
|
|
360
|
+
* @returns {string} SGR escape sequence.
|
|
361
|
+
*/
|
|
158
362
|
export const setColor256 = (r, g, b) => setCommands(getColor256(r, g, b));
|
|
159
|
-
|
|
363
|
+
/** Sets foreground 256-color by hex.
|
|
364
|
+
* @param {number} hex - Hex color value.
|
|
365
|
+
* @returns {string} SGR escape sequence.
|
|
366
|
+
*/
|
|
367
|
+
export const setHexColor256 = hex => setCommands(getHexColor256(hex));
|
|
368
|
+
/** Sets foreground 256-color gray by index.
|
|
369
|
+
* @param {number} i - Gray index (0-23).
|
|
370
|
+
* @returns {string} SGR escape sequence.
|
|
371
|
+
*/
|
|
160
372
|
export const setGrayColor24 = i => setCommands(getGrayColor24(i));
|
|
373
|
+
/** Sets foreground 256-color gray by intensity.
|
|
374
|
+
* @param {number} i - Gray intensity (0-255).
|
|
375
|
+
* @returns {string} SGR escape sequence.
|
|
376
|
+
*/
|
|
161
377
|
export const setGrayColor256 = i => setCommands(getGrayColor256(i));
|
|
162
378
|
|
|
379
|
+
/** Returns background 256-color command array for a raw palette index.
|
|
380
|
+
* @param {number} color - Palette index (0-255).
|
|
381
|
+
* @returns {string[]}
|
|
382
|
+
*/
|
|
163
383
|
export const getBgRawColor256 = color => [Commands.BG_EXTENDED_COLOR, ColorFormat.COLOR_256, color];
|
|
164
|
-
|
|
384
|
+
/** Returns background 256-color command array for a standard color.
|
|
385
|
+
* @param {string|number} color - Color name or number.
|
|
386
|
+
* @returns {string[]}
|
|
387
|
+
*/
|
|
388
|
+
export const getBgStdColor256 = color => getBgRawColor256(colorNumber(color));
|
|
389
|
+
/** Returns background 256-color command array for a bright standard color.
|
|
390
|
+
* @param {string|number} color - Color name or number.
|
|
391
|
+
* @returns {string[]}
|
|
392
|
+
*/
|
|
165
393
|
export const getBgBrightStdColor256 = color => getBgStdColor256(8 + colorNumber(color));
|
|
394
|
+
/** Returns background 256-color command array for a 6x6x6 RGB color.
|
|
395
|
+
* @param {number} r - Red (0-5).
|
|
396
|
+
* @param {number} g - Green (0-5).
|
|
397
|
+
* @param {number} b - Blue (0-5).
|
|
398
|
+
* @returns {string[]}
|
|
399
|
+
*/
|
|
166
400
|
export const getBgColor6 = (r, g, b) => getBgRawColor256(16 + 36 * lim5(r) + 6 * lim5(g) + lim5(b));
|
|
401
|
+
/** Returns background 256-color command array for an RGB color.
|
|
402
|
+
* @param {number} r - Red (0-255).
|
|
403
|
+
* @param {number} g - Green (0-255).
|
|
404
|
+
* @param {number} b - Blue (0-255).
|
|
405
|
+
* @returns {string[]}
|
|
406
|
+
*/
|
|
167
407
|
export const getBgColor256 = (r, g, b) => getBgColor6(get6(r), get6(g), get6(b));
|
|
408
|
+
/** Returns background 256-color command array for a hex color.
|
|
409
|
+
* @param {number} hex - Hex color value.
|
|
410
|
+
* @returns {string[]}
|
|
411
|
+
*/
|
|
168
412
|
export const getBgHexColor256 = hex => getBgColor256((hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff);
|
|
413
|
+
/** Returns background 256-color command array for a 24-shade gray.
|
|
414
|
+
* @param {number} i - Gray index (0-23).
|
|
415
|
+
* @returns {string[]}
|
|
416
|
+
*/
|
|
169
417
|
export const getBgGrayColor24 = i => getBgRawColor256(232 + lim23(i));
|
|
418
|
+
/** Returns background 256-color command array for a gray by intensity.
|
|
419
|
+
* @param {number} i - Gray intensity (0-255).
|
|
420
|
+
* @returns {string[]}
|
|
421
|
+
*/
|
|
170
422
|
export const getBgGrayColor256 = i => getBgGrayColor24(get24(i));
|
|
171
423
|
|
|
424
|
+
/** Sets background 256-color by raw palette index.
|
|
425
|
+
* @param {number} color - Palette index (0-255).
|
|
426
|
+
* @returns {string} SGR escape sequence.
|
|
427
|
+
*/
|
|
172
428
|
export const setBgRawColor256 = color => setCommands(getBgRawColor256(color));
|
|
429
|
+
/** Sets background 256-color by standard color.
|
|
430
|
+
* @param {string|number} color - Color name or number.
|
|
431
|
+
* @returns {string} SGR escape sequence.
|
|
432
|
+
*/
|
|
173
433
|
export const setBgStdColor256 = color => setCommands(getBgStdColor256(color));
|
|
434
|
+
/** Sets background 256-color by bright standard color.
|
|
435
|
+
* @param {string|number} color - Color name or number.
|
|
436
|
+
* @returns {string} SGR escape sequence.
|
|
437
|
+
*/
|
|
174
438
|
export const setBgBrightStdColor256 = color => setCommands(getBgBrightStdColor256(color));
|
|
439
|
+
/** Sets background 256-color by 6x6x6 RGB.
|
|
440
|
+
* @param {number} r - Red (0-5).
|
|
441
|
+
* @param {number} g - Green (0-5).
|
|
442
|
+
* @param {number} b - Blue (0-5).
|
|
443
|
+
* @returns {string} SGR escape sequence.
|
|
444
|
+
*/
|
|
175
445
|
export const setBgColor6 = (r, g, b) => setCommands(getBgColor6(r, g, b));
|
|
446
|
+
/** Sets background 256-color by RGB.
|
|
447
|
+
* @param {number} r - Red (0-255).
|
|
448
|
+
* @param {number} g - Green (0-255).
|
|
449
|
+
* @param {number} b - Blue (0-255).
|
|
450
|
+
* @returns {string} SGR escape sequence.
|
|
451
|
+
*/
|
|
176
452
|
export const setBgColor256 = (r, g, b) => setCommands(getBgColor256(r, g, b));
|
|
177
|
-
|
|
453
|
+
/** Sets background 256-color by hex.
|
|
454
|
+
* @param {number} hex - Hex color value.
|
|
455
|
+
* @returns {string} SGR escape sequence.
|
|
456
|
+
*/
|
|
457
|
+
export const setBgHexColor256 = hex => setCommands(getBgHexColor256(hex));
|
|
458
|
+
/** Sets background 256-color gray by index.
|
|
459
|
+
* @param {number} i - Gray index (0-23).
|
|
460
|
+
* @returns {string} SGR escape sequence.
|
|
461
|
+
*/
|
|
178
462
|
export const setBgGrayColor24 = i => setCommands(getBgGrayColor24(i));
|
|
179
|
-
|
|
463
|
+
/** Sets background 256-color gray by intensity.
|
|
464
|
+
* @param {number} i - Gray intensity (0-255).
|
|
465
|
+
* @returns {string} SGR escape sequence.
|
|
466
|
+
*/
|
|
467
|
+
export const setBgGrayColor256 = i => setCommands(getBgGrayColor256(i));
|
|
180
468
|
|
|
469
|
+
/** Returns the foreground true color (24-bit) SGR command array.
|
|
470
|
+
* @param {number} r - Red (0-255).
|
|
471
|
+
* @param {number} g - Green (0-255).
|
|
472
|
+
* @param {number} b - Blue (0-255).
|
|
473
|
+
* @returns {string[]}
|
|
474
|
+
*/
|
|
181
475
|
export const getTrueColor = (r, g, b) => [Commands.EXTENDED_COLOR, ColorFormat.TRUE_COLOR, r, g, b];
|
|
476
|
+
/** Returns the foreground true color command array from hex.
|
|
477
|
+
* @param {number} hex - Hex color value.
|
|
478
|
+
* @returns {string[]}
|
|
479
|
+
*/
|
|
182
480
|
export const getHexTrueColor = hex => getTrueColor((hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff);
|
|
481
|
+
/** Returns the background true color (24-bit) SGR command array.
|
|
482
|
+
* @param {number} r - Red (0-255).
|
|
483
|
+
* @param {number} g - Green (0-255).
|
|
484
|
+
* @param {number} b - Blue (0-255).
|
|
485
|
+
* @returns {string[]}
|
|
486
|
+
*/
|
|
183
487
|
export const getBgTrueColor = (r, g, b) => [Commands.BG_EXTENDED_COLOR, ColorFormat.TRUE_COLOR, r, g, b];
|
|
488
|
+
/** Returns the background true color command array from hex.
|
|
489
|
+
* @param {number} hex - Hex color value.
|
|
490
|
+
* @returns {string[]}
|
|
491
|
+
*/
|
|
184
492
|
export const getBgHexTrueColor = hex => getBgTrueColor((hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff);
|
|
185
493
|
|
|
494
|
+
/** Sets foreground true color.
|
|
495
|
+
* @param {number} r - Red (0-255).
|
|
496
|
+
* @param {number} g - Green (0-255).
|
|
497
|
+
* @param {number} b - Blue (0-255).
|
|
498
|
+
* @returns {string} SGR escape sequence.
|
|
499
|
+
*/
|
|
186
500
|
export const setTrueColor = (r, g, b) => setCommands(getTrueColor(r, g, b));
|
|
501
|
+
/** Sets foreground true color from hex.
|
|
502
|
+
* @param {number} hex - Hex color value.
|
|
503
|
+
* @returns {string} SGR escape sequence.
|
|
504
|
+
*/
|
|
187
505
|
export const setHexTrueColor = hex => setCommands(getHexTrueColor(hex));
|
|
506
|
+
/** Sets background true color.
|
|
507
|
+
* @param {number} r - Red (0-255).
|
|
508
|
+
* @param {number} g - Green (0-255).
|
|
509
|
+
* @param {number} b - Blue (0-255).
|
|
510
|
+
* @returns {string} SGR escape sequence.
|
|
511
|
+
*/
|
|
188
512
|
export const setBgTrueColor = (r, g, b) => setCommands(getBgTrueColor(r, g, b));
|
|
513
|
+
/** Sets background true color from hex.
|
|
514
|
+
* @param {number} hex - Hex color value.
|
|
515
|
+
* @returns {string} SGR escape sequence.
|
|
516
|
+
*/
|
|
189
517
|
export const setBgHexTrueColor = hex => setCommands(getBgHexTrueColor(hex));
|
|
190
518
|
|
|
519
|
+
/** Returns decoration 256-color command array for a raw palette index.
|
|
520
|
+
* @param {number} color - Palette index (0-255).
|
|
521
|
+
* @returns {string[]}
|
|
522
|
+
*/
|
|
191
523
|
export const getDecorationRawColor256 = color => [Commands.DECORATION_COLOR, ColorFormat.COLOR_256, color];
|
|
524
|
+
/** Returns decoration 256-color command array for a standard color.
|
|
525
|
+
* @param {string|number} color - Color name or number.
|
|
526
|
+
* @returns {string[]}
|
|
527
|
+
*/
|
|
192
528
|
export const getDecorationStdColor256 = color => getDecorationRawColor256(colorNumber(color));
|
|
529
|
+
/** Returns decoration 256-color command array for a bright standard color.
|
|
530
|
+
* @param {string|number} color - Color name or number.
|
|
531
|
+
* @returns {string[]}
|
|
532
|
+
*/
|
|
193
533
|
export const getDecorationBrightStdColor256 = color => getDecorationRawColor256(8 + colorNumber(color));
|
|
534
|
+
/** Returns decoration 256-color command array for a 6x6x6 RGB color.
|
|
535
|
+
* @param {number} r - Red (0-5).
|
|
536
|
+
* @param {number} g - Green (0-5).
|
|
537
|
+
* @param {number} b - Blue (0-5).
|
|
538
|
+
* @returns {string[]}
|
|
539
|
+
*/
|
|
194
540
|
export const getDecorationColor6 = (r, g, b) => getDecorationRawColor256(16 + 36 * lim5(r) + 6 * lim5(g) + lim5(b));
|
|
541
|
+
/** Returns decoration 256-color command array for an RGB color.
|
|
542
|
+
* @param {number} r - Red (0-255).
|
|
543
|
+
* @param {number} g - Green (0-255).
|
|
544
|
+
* @param {number} b - Blue (0-255).
|
|
545
|
+
* @returns {string[]}
|
|
546
|
+
*/
|
|
195
547
|
export const getDecorationColor256 = (r, g, b) => getDecorationColor6(get6(r), get6(g), get6(b));
|
|
548
|
+
/** Returns decoration 256-color command array for a hex color.
|
|
549
|
+
* @param {number} hex - Hex color value.
|
|
550
|
+
* @returns {string[]}
|
|
551
|
+
*/
|
|
196
552
|
export const getDecorationHexColor256 = hex => getDecorationColor256((hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff);
|
|
553
|
+
/** Returns decoration 256-color command array for a 24-shade gray.
|
|
554
|
+
* @param {number} i - Gray index (0-23).
|
|
555
|
+
* @returns {string[]}
|
|
556
|
+
*/
|
|
197
557
|
export const getDecorationGrayColor24 = i => getDecorationRawColor256(232 + lim23(i));
|
|
558
|
+
/** Returns decoration 256-color command array for a gray by intensity.
|
|
559
|
+
* @param {number} i - Gray intensity (0-255).
|
|
560
|
+
* @returns {string[]}
|
|
561
|
+
*/
|
|
198
562
|
export const getDecorationGrayColor256 = i => getDecorationGrayColor24(get24(i));
|
|
199
563
|
|
|
564
|
+
/** Sets decoration 256-color by raw palette index.
|
|
565
|
+
* @param {number} color - Palette index (0-255).
|
|
566
|
+
* @returns {string} SGR escape sequence.
|
|
567
|
+
*/
|
|
200
568
|
export const setDecorationRawColor256 = color => setCommands(getDecorationRawColor256(color));
|
|
569
|
+
/** Sets decoration 256-color by standard color.
|
|
570
|
+
* @param {string|number} color - Color name or number.
|
|
571
|
+
* @returns {string} SGR escape sequence.
|
|
572
|
+
*/
|
|
201
573
|
export const setDecorationStdColor256 = color => setCommands(getDecorationStdColor256(color));
|
|
574
|
+
/** Sets decoration 256-color by bright standard color.
|
|
575
|
+
* @param {string|number} color - Color name or number.
|
|
576
|
+
* @returns {string} SGR escape sequence.
|
|
577
|
+
*/
|
|
202
578
|
export const setDecorationBrightStdColor256 = color => setCommands(getDecorationBrightStdColor256(color));
|
|
579
|
+
/** Sets decoration 256-color by 6x6x6 RGB.
|
|
580
|
+
* @param {number} r - Red (0-5).
|
|
581
|
+
* @param {number} g - Green (0-5).
|
|
582
|
+
* @param {number} b - Blue (0-5).
|
|
583
|
+
* @returns {string} SGR escape sequence.
|
|
584
|
+
*/
|
|
203
585
|
export const setDecorationColor6 = (r, g, b) => setCommands(getDecorationColor6(r, g, b));
|
|
586
|
+
/** Sets decoration 256-color by RGB.
|
|
587
|
+
* @param {number} r - Red (0-255).
|
|
588
|
+
* @param {number} g - Green (0-255).
|
|
589
|
+
* @param {number} b - Blue (0-255).
|
|
590
|
+
* @returns {string} SGR escape sequence.
|
|
591
|
+
*/
|
|
204
592
|
export const setDecorationColor256 = (r, g, b) => setCommands(getDecorationColor256(r, g, b));
|
|
205
|
-
|
|
593
|
+
/** Sets decoration 256-color by hex.
|
|
594
|
+
* @param {number} hex - Hex color value.
|
|
595
|
+
* @returns {string} SGR escape sequence.
|
|
596
|
+
*/
|
|
597
|
+
export const setDecorationHexColor256 = hex => setCommands(getDecorationHexColor256(hex));
|
|
598
|
+
/** Sets decoration 256-color gray by index.
|
|
599
|
+
* @param {number} i - Gray index (0-23).
|
|
600
|
+
* @returns {string} SGR escape sequence.
|
|
601
|
+
*/
|
|
206
602
|
export const setDecorationGrayColor24 = i => setCommands(getDecorationGrayColor24(i));
|
|
603
|
+
/** Sets decoration 256-color gray by intensity.
|
|
604
|
+
* @param {number} i - Gray intensity (0-255).
|
|
605
|
+
* @returns {string} SGR escape sequence.
|
|
606
|
+
*/
|
|
207
607
|
export const setDecorationGrayColor256 = i => setCommands(getDecorationGrayColor256(i));
|
|
208
608
|
|
|
609
|
+
/** Returns decoration true color command array.
|
|
610
|
+
* @param {number} r - Red (0-255).
|
|
611
|
+
* @param {number} g - Green (0-255).
|
|
612
|
+
* @param {number} b - Blue (0-255).
|
|
613
|
+
* @returns {string[]}
|
|
614
|
+
*/
|
|
209
615
|
export const getDecorationTrueColor = (r, g, b) => [Commands.DECORATION_COLOR, ColorFormat.TRUE_COLOR, r, g, b];
|
|
616
|
+
/** Returns decoration true color command array from hex.
|
|
617
|
+
* @param {number} hex - Hex color value.
|
|
618
|
+
* @returns {string[]}
|
|
619
|
+
*/
|
|
210
620
|
export const getDecorationHexTrueColor = hex =>
|
|
211
621
|
getDecorationTrueColor((hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff);
|
|
212
622
|
|
|
623
|
+
/** Sets decoration true color.
|
|
624
|
+
* @param {number} r - Red (0-255).
|
|
625
|
+
* @param {number} g - Green (0-255).
|
|
626
|
+
* @param {number} b - Blue (0-255).
|
|
627
|
+
* @returns {string} SGR escape sequence.
|
|
628
|
+
*/
|
|
213
629
|
export const setDecorationTrueColor = (r, g, b) => setCommands(getDecorationTrueColor(r, g, b));
|
|
630
|
+
/** Sets decoration true color from hex.
|
|
631
|
+
* @param {number} hex - Hex color value.
|
|
632
|
+
* @returns {string} SGR escape sequence.
|
|
633
|
+
*/
|
|
214
634
|
export const setDecorationHexTrueColor = hex => setCommands(getDecorationHexTrueColor(hex));
|