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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** A single grapheme with its display width. */
|
|
2
|
+
export interface Grapheme {
|
|
3
|
+
/** The grapheme string. */
|
|
4
|
+
symbol: string;
|
|
5
|
+
/** The display width in columns. */
|
|
6
|
+
width: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Result of splitting a string into graphemes. */
|
|
10
|
+
export interface SplitResult {
|
|
11
|
+
/** Array of graphemes. */
|
|
12
|
+
graphemes: Grapheme[];
|
|
13
|
+
/** Total display width. */
|
|
14
|
+
width: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Options for `split()` and `size()`. */
|
|
18
|
+
export interface SplitOptions {
|
|
19
|
+
/** If true, ignore control symbols. */
|
|
20
|
+
ignoreControlSymbols?: boolean;
|
|
21
|
+
/** If true, treat East Asian ambiguous-width characters as wide. */
|
|
22
|
+
ambiguousAsWide?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Splits a string into graphemes with their display widths.
|
|
26
|
+
* @param s - The string to split.
|
|
27
|
+
* @param options - Split options.
|
|
28
|
+
* @returns The graphemes and total width.
|
|
29
|
+
*/
|
|
30
|
+
export function split(s: string, options?: SplitOptions): SplitResult;
|
|
31
|
+
/** Returns the display width of a string.
|
|
32
|
+
* @param s - The string to measure.
|
|
33
|
+
* @param options - Split options.
|
|
34
|
+
* @returns The display width in columns.
|
|
35
|
+
*/
|
|
36
|
+
export function size(s: string, options?: SplitOptions): number;
|
|
37
|
+
|
|
38
|
+
export default split;
|
package/src/strings/split.js
CHANGED
|
@@ -18,6 +18,14 @@ if (!globalThis.Bun) {
|
|
|
18
18
|
|
|
19
19
|
const segmenter = new Intl.Segmenter();
|
|
20
20
|
|
|
21
|
+
/** Splits a string into graphemes (individual symbols) and calculates its display width.
|
|
22
|
+
* Optionally detects double-width characters using `emoji-regex` and `get-east-asian-width` if available.
|
|
23
|
+
* @param {string} s - The string to split.
|
|
24
|
+
* @param {object} [options] - Options.
|
|
25
|
+
* @param {boolean} [options.ignoreControlSymbols=false] - If true, control symbols are ignored.
|
|
26
|
+
* @param {boolean} [options.ambiguousAsWide=false] - If true, ambiguous East Asian characters are treated as double-wide.
|
|
27
|
+
* @returns {{graphemes: {symbol: string, width: number}[], width: number}} The graphemes and total display width.
|
|
28
|
+
*/
|
|
21
29
|
export const split = (s, options = {}) => {
|
|
22
30
|
s = String(s);
|
|
23
31
|
if (!s) return {graphemes: [], width: 0};
|
|
@@ -66,6 +74,13 @@ export const split = (s, options = {}) => {
|
|
|
66
74
|
return {graphemes, width};
|
|
67
75
|
};
|
|
68
76
|
|
|
77
|
+
/** Calculates the display width of a string, accounting for double-width characters.
|
|
78
|
+
* @param {string} s - The string to measure.
|
|
79
|
+
* @param {object} [options] - Options.
|
|
80
|
+
* @param {boolean} [options.ignoreControlSymbols=false] - If true, control symbols are ignored.
|
|
81
|
+
* @param {boolean} [options.ambiguousAsWide=false] - If true, ambiguous East Asian characters are treated as double-wide.
|
|
82
|
+
* @returns {number} The display width of the string.
|
|
83
|
+
*/
|
|
69
84
|
export const size = (s, options = {}) => {
|
|
70
85
|
s = String(s);
|
|
71
86
|
if (!s) return 0;
|
package/src/strings.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {ClipOptions} from './strings/clip.js';
|
|
2
|
+
|
|
3
|
+
/** Returns the display width of a string, ignoring ANSI escape sequences.
|
|
4
|
+
* @param s - The string to measure.
|
|
5
|
+
* @param matcher - RegExp for matching escape sequences (default: matchCsiNoGroups).
|
|
6
|
+
* @returns The visible display width.
|
|
7
|
+
*/
|
|
8
|
+
export function getLength(s: string, matcher?: RegExp): number;
|
|
9
|
+
/** Returns the maximum display width among an array of strings.
|
|
10
|
+
* @param strings - The strings to measure.
|
|
11
|
+
* @param matcher - RegExp for matching escape sequences.
|
|
12
|
+
* @returns The maximum display width.
|
|
13
|
+
*/
|
|
14
|
+
export function getMaxLength(strings: string[], matcher?: RegExp): number;
|
|
15
|
+
/** Clips each string in an array to a given display width.
|
|
16
|
+
* @param strings - The strings to clip.
|
|
17
|
+
* @param width - Maximum display width.
|
|
18
|
+
* @param options - Clip options.
|
|
19
|
+
* @returns The clipped strings.
|
|
20
|
+
*/
|
|
21
|
+
export function clipStrings(strings: string[], width: number, options?: ClipOptions): string[];
|
|
22
|
+
|
|
23
|
+
export type StringsValue =
|
|
24
|
+
| null
|
|
25
|
+
| undefined
|
|
26
|
+
| boolean
|
|
27
|
+
| number
|
|
28
|
+
| string
|
|
29
|
+
| string[]
|
|
30
|
+
| object
|
|
31
|
+
| {toStrings(): string[]}
|
|
32
|
+
| {toBox(): {box: string[]}}
|
|
33
|
+
| {toPanel(): {toStrings(): string[]}};
|
|
34
|
+
export type StringsFunction = () => StringsFunction | StringsValue;
|
|
35
|
+
export type StringsInput = StringsValue | StringsFunction;
|
|
36
|
+
|
|
37
|
+
/** Converts various input types to a string array.
|
|
38
|
+
* @param s - Input: string, string array, Box, number, null/undefined, or object with `toStrings()`.
|
|
39
|
+
* @returns An array of strings.
|
|
40
|
+
*/
|
|
41
|
+
export function toStrings(s: StringsInput): string[];
|
|
42
|
+
|
|
43
|
+
export {default as clip} from './strings/clip.js';
|
|
44
|
+
export {matchCsiNoGroups, matchCsiNoSgrNoGroups} from './strings/parse.js';
|
package/src/strings.js
CHANGED
|
@@ -2,6 +2,12 @@ import {size} from './strings/split.js';
|
|
|
2
2
|
import parse, {matchCsiNoGroups, matchCsiNoSgrNoGroups} from './strings/parse.js';
|
|
3
3
|
import clip from './strings/clip.js';
|
|
4
4
|
|
|
5
|
+
/** Returns the visible display length of a string, excluding invisible ANSI escape sequences
|
|
6
|
+
* and correctly handling Unicode code points that span multiple UTF-16 items.
|
|
7
|
+
* @param {string} s - The string to measure.
|
|
8
|
+
* @param {RegExp} [matcher=matchCsiNoGroups] - The regular expression used to match escape sequences.
|
|
9
|
+
* @returns {number} The visible display length.
|
|
10
|
+
*/
|
|
5
11
|
export const getLength = (s, matcher) => {
|
|
6
12
|
let counter = 0;
|
|
7
13
|
for (const {string} of parse(s, matcher)) {
|
|
@@ -10,12 +16,36 @@ export const getLength = (s, matcher) => {
|
|
|
10
16
|
return counter;
|
|
11
17
|
};
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
/** Returns the maximum visible display length among an array of strings.
|
|
20
|
+
* @param {string[]} strings - The strings to measure.
|
|
21
|
+
* @param {RegExp} [matcher=matchCsiNoGroups] - The regular expression used to match escape sequences.
|
|
22
|
+
* @returns {number} The maximum visible display length.
|
|
23
|
+
*/
|
|
24
|
+
export const getMaxLength = (strings, matcher) => strings.reduce((acc, s) => Math.max(acc, getLength(s, matcher)), 0);
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
/** Clips each string in an array to a specified display width.
|
|
27
|
+
* @param {string[]} strings - The strings to clip.
|
|
28
|
+
* @param {number} width - The maximum display width.
|
|
29
|
+
* @param {object} [options] - Options passed to `clip()`.
|
|
30
|
+
* @returns {string[]} The clipped strings.
|
|
31
|
+
*/
|
|
32
|
+
export const clipStrings = (strings, width, options) => strings.map(s => clip(s, width, options));
|
|
18
33
|
|
|
34
|
+
/** Converts a variety of inputs into an array of strings (the simplest text container).
|
|
35
|
+
*
|
|
36
|
+
* - A function is called (up to 10 times) and its result is re-processed.
|
|
37
|
+
* - A number or boolean returns `[String(s)]`.
|
|
38
|
+
* - A string is split by newlines.
|
|
39
|
+
* - An array is shallow-copied.
|
|
40
|
+
* - An object with `toStrings()` is called.
|
|
41
|
+
* - An object with `toBox()` returns `toBox().box`.
|
|
42
|
+
* - An object with `toPanel()` returns `toPanel().toStrings()`.
|
|
43
|
+
* - Other non-null objects are converted via `String()`.
|
|
44
|
+
* - Null/undefined returns `[]`.
|
|
45
|
+
*
|
|
46
|
+
* @param {*} s - The input to convert.
|
|
47
|
+
* @returns {string[]} An array of strings.
|
|
48
|
+
*/
|
|
19
49
|
export const toStrings = s => {
|
|
20
50
|
main: for (;;) {
|
|
21
51
|
switch (typeof s) {
|
package/src/style.d.ts
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
import {SgrState} from './ansi/sgr-state.js';
|
|
2
|
+
|
|
3
|
+
export {RESET_STATE} from './ansi/sgr-state.js';
|
|
4
|
+
|
|
5
|
+
/** Methods available on color namespace objects (fg, bg, colorDecoration). */
|
|
6
|
+
interface ColorMethods {
|
|
7
|
+
/** Sets color by standard color number.
|
|
8
|
+
* @param c - Color number (0-9).
|
|
9
|
+
* @returns A new Style.
|
|
10
|
+
*/
|
|
11
|
+
color(c: number): Style;
|
|
12
|
+
/** Sets 256-color by standard RGB.
|
|
13
|
+
* @param r - Red (0-5).
|
|
14
|
+
* @param g - Green (0-5).
|
|
15
|
+
* @param b - Blue (0-5).
|
|
16
|
+
* @returns A new Style.
|
|
17
|
+
*/
|
|
18
|
+
stdRgb256(r: number, g: number, b: number): Style;
|
|
19
|
+
/** Sets bright 256-color by standard RGB.
|
|
20
|
+
* @returns A new Style.
|
|
21
|
+
*/
|
|
22
|
+
brightStdRgb256(r: number, g: number, b: number): Style;
|
|
23
|
+
/** Sets dark 256-color by standard RGB.
|
|
24
|
+
* @returns A new Style.
|
|
25
|
+
*/
|
|
26
|
+
darkStdRgb256(r: number, g: number, b: number): Style;
|
|
27
|
+
/** Sets color by standard RGB (alias for stdRgb256).
|
|
28
|
+
* @returns A new Style.
|
|
29
|
+
*/
|
|
30
|
+
stdRgb(r: number, g: number, b: number): Style;
|
|
31
|
+
/** Sets bright color by standard RGB (alias for brightStdRgb256).
|
|
32
|
+
* @returns A new Style.
|
|
33
|
+
*/
|
|
34
|
+
brightStdRgb(r: number, g: number, b: number): Style;
|
|
35
|
+
/** Sets dark color by standard RGB (alias for darkStdRgb256).
|
|
36
|
+
* @returns A new Style.
|
|
37
|
+
*/
|
|
38
|
+
darkStdRgb(r: number, g: number, b: number): Style;
|
|
39
|
+
/** Sets 256-color by RGB.
|
|
40
|
+
* @param r - Red (0-255).
|
|
41
|
+
* @param g - Green (0-255).
|
|
42
|
+
* @param b - Blue (0-255).
|
|
43
|
+
* @returns A new Style.
|
|
44
|
+
*/
|
|
45
|
+
rgb256(r: number, g: number, b: number): Style;
|
|
46
|
+
/** Sets 256-color by hex.
|
|
47
|
+
* @param hex - Hex color value.
|
|
48
|
+
* @returns A new Style.
|
|
49
|
+
*/
|
|
50
|
+
hex256(hex: number): Style;
|
|
51
|
+
/** Sets 256-color by 6x6x6 RGB.
|
|
52
|
+
* @param r - Red (0-5).
|
|
53
|
+
* @param g - Green (0-5).
|
|
54
|
+
* @param b - Blue (0-5).
|
|
55
|
+
* @returns A new Style.
|
|
56
|
+
*/
|
|
57
|
+
rgb6(r: number, g: number, b: number): Style;
|
|
58
|
+
/** Sets 256-color grayscale by intensity.
|
|
59
|
+
* @param i - Intensity (0-255).
|
|
60
|
+
* @returns A new Style.
|
|
61
|
+
*/
|
|
62
|
+
grayscale256(i: number): Style;
|
|
63
|
+
/** Sets 256-color grayscale by index.
|
|
64
|
+
* @param i - Index (0-23).
|
|
65
|
+
* @returns A new Style.
|
|
66
|
+
*/
|
|
67
|
+
grayscale24(i: number): Style;
|
|
68
|
+
/** Sets true color by RGB.
|
|
69
|
+
* @param r - Red (0-255).
|
|
70
|
+
* @param g - Green (0-255).
|
|
71
|
+
* @param b - Blue (0-255).
|
|
72
|
+
* @returns A new Style.
|
|
73
|
+
*/
|
|
74
|
+
trueColor(r: number, g: number, b: number): Style;
|
|
75
|
+
/** Sets true color grayscale.
|
|
76
|
+
* @param i - Intensity (0-255).
|
|
77
|
+
* @returns A new Style.
|
|
78
|
+
*/
|
|
79
|
+
trueGrayscale(i: number): Style;
|
|
80
|
+
/** Sets true color by hex.
|
|
81
|
+
* @param hex - Hex color value.
|
|
82
|
+
* @returns A new Style.
|
|
83
|
+
*/
|
|
84
|
+
hexTrueColor(hex: number): Style;
|
|
85
|
+
/** Sets color by RGB (auto-selects true color or 256-color based on depth).
|
|
86
|
+
* @returns A new Style.
|
|
87
|
+
*/
|
|
88
|
+
rgb(r: number, g: number, b: number): Style;
|
|
89
|
+
/** Sets grayscale (auto-selects based on depth).
|
|
90
|
+
* @param i - Intensity.
|
|
91
|
+
* @returns A new Style.
|
|
92
|
+
*/
|
|
93
|
+
grayscale(i: number): Style;
|
|
94
|
+
/** Sets color by hex (auto-selects based on depth).
|
|
95
|
+
* @param hex - Hex color value.
|
|
96
|
+
* @returns A new Style.
|
|
97
|
+
*/
|
|
98
|
+
hex(hex: number): Style;
|
|
99
|
+
|
|
100
|
+
/** Switches to bright color mode. */
|
|
101
|
+
readonly bright: this;
|
|
102
|
+
/** Switches to dark (standard) color mode. */
|
|
103
|
+
readonly dark: this;
|
|
104
|
+
/** Resets to default color. */
|
|
105
|
+
readonly default: Style;
|
|
106
|
+
|
|
107
|
+
// standard color getters
|
|
108
|
+
readonly black: Style;
|
|
109
|
+
readonly red: Style;
|
|
110
|
+
readonly green: Style;
|
|
111
|
+
readonly yellow: Style;
|
|
112
|
+
readonly blue: Style;
|
|
113
|
+
readonly magenta: Style;
|
|
114
|
+
readonly cyan: Style;
|
|
115
|
+
readonly white: Style;
|
|
116
|
+
readonly brightBlack: Style;
|
|
117
|
+
readonly brightRed: Style;
|
|
118
|
+
readonly brightGreen: Style;
|
|
119
|
+
readonly brightYellow: Style;
|
|
120
|
+
readonly brightBlue: Style;
|
|
121
|
+
readonly brightMagenta: Style;
|
|
122
|
+
readonly brightCyan: Style;
|
|
123
|
+
readonly brightWhite: Style;
|
|
124
|
+
readonly darkBlack: Style;
|
|
125
|
+
readonly darkRed: Style;
|
|
126
|
+
readonly darkGreen: Style;
|
|
127
|
+
readonly darkYellow: Style;
|
|
128
|
+
readonly darkBlue: Style;
|
|
129
|
+
readonly darkMagenta: Style;
|
|
130
|
+
readonly darkCyan: Style;
|
|
131
|
+
readonly darkWhite: Style;
|
|
132
|
+
readonly gray: Style;
|
|
133
|
+
readonly grey: Style;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Chainable API for building SGR (Select Graphics Rendition) states.
|
|
137
|
+
* @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-style}
|
|
138
|
+
*/
|
|
139
|
+
export class Style {
|
|
140
|
+
/**
|
|
141
|
+
* @param initState - The initial SGR state (SgrState, string, or null for reset).
|
|
142
|
+
* @param currentState - The current SGR state (defaults to initState).
|
|
143
|
+
* @param colorDepth - Color depth (1, 4, 8, or 24; default: 24).
|
|
144
|
+
*/
|
|
145
|
+
constructor(initState: SgrState | string | null, currentState?: SgrState | string | null, colorDepth?: number);
|
|
146
|
+
|
|
147
|
+
/** Creates a new Style with additional SGR commands applied.
|
|
148
|
+
* @param newCommands - SGR command(s) to add.
|
|
149
|
+
* @returns A new Style.
|
|
150
|
+
*/
|
|
151
|
+
make(newCommands?: string | number | (string | number)[]): Style;
|
|
152
|
+
/** Alias for `make`. */
|
|
153
|
+
addCommands: Style['make'];
|
|
154
|
+
/** Adds SGR commands from an escape sequence string.
|
|
155
|
+
* @param commandSequence - An ANSI escape sequence string.
|
|
156
|
+
* @returns A new Style.
|
|
157
|
+
*/
|
|
158
|
+
add(commandSequence: string): Style;
|
|
159
|
+
/** Combines an SGR state into the current state.
|
|
160
|
+
* @param state - State to combine (SgrState, string, or null).
|
|
161
|
+
* @returns A new Style.
|
|
162
|
+
*/
|
|
163
|
+
addState(state: SgrState | string | null): Style;
|
|
164
|
+
/** Creates a new Style with the current state as the initial state.
|
|
165
|
+
* @param fn - Optional callback receiving the new Style. If provided, returns `this` instead.
|
|
166
|
+
* @returns A new Style, or `this` if `fn` is provided.
|
|
167
|
+
*/
|
|
168
|
+
mark(fn?: (style: Style) => void): Style;
|
|
169
|
+
/** Returns the initial state, or passes it to a callback.
|
|
170
|
+
* @param fn - Optional callback. If provided, returns `this` instead.
|
|
171
|
+
* @returns The initial SgrState, or `this` if `fn` is provided.
|
|
172
|
+
*/
|
|
173
|
+
getInitialState(fn?: (state: SgrState) => void): SgrState | Style;
|
|
174
|
+
/** Returns the current state, or passes it to a callback.
|
|
175
|
+
* @param fn - Optional callback. If provided, returns `this` instead.
|
|
176
|
+
* @returns The current SgrState, or `this` if `fn` is provided.
|
|
177
|
+
*/
|
|
178
|
+
getState(fn?: (state: SgrState) => void): SgrState | Style;
|
|
179
|
+
|
|
180
|
+
/** The color depth (1, 4, 8, or 24). */
|
|
181
|
+
readonly colorDepth: number;
|
|
182
|
+
/** Creates a new Style with a different color depth.
|
|
183
|
+
* @param colorDepth - Color depth (1, 4, 8, or 24).
|
|
184
|
+
* @returns A new Style.
|
|
185
|
+
*/
|
|
186
|
+
setColorDepth(colorDepth: number): Style;
|
|
187
|
+
|
|
188
|
+
/** Foreground color namespace. */
|
|
189
|
+
readonly fg: ColorMethods;
|
|
190
|
+
/** Background color namespace. */
|
|
191
|
+
readonly bg: ColorMethods;
|
|
192
|
+
/** Foreground color namespace (alias for `fg`). */
|
|
193
|
+
readonly foreground: ColorMethods;
|
|
194
|
+
/** Background color namespace (alias for `bg`). */
|
|
195
|
+
readonly background: ColorMethods;
|
|
196
|
+
/** Decoration (underline) color namespace. */
|
|
197
|
+
readonly colorDecoration: ColorMethods;
|
|
198
|
+
/** Decoration color namespace (alias for `colorDecoration`). */
|
|
199
|
+
readonly decoration: ColorMethods;
|
|
200
|
+
|
|
201
|
+
/** Reset namespace — each property returns a Style with that attribute reset. */
|
|
202
|
+
readonly reset: {
|
|
203
|
+
/** Resets all attributes. */
|
|
204
|
+
readonly all: Style;
|
|
205
|
+
readonly bold: Style;
|
|
206
|
+
readonly dim: Style;
|
|
207
|
+
readonly italic: Style;
|
|
208
|
+
readonly underline: Style;
|
|
209
|
+
readonly blink: Style;
|
|
210
|
+
readonly rapidBlink: Style;
|
|
211
|
+
readonly inverse: Style;
|
|
212
|
+
readonly hidden: Style;
|
|
213
|
+
readonly strikethrough: Style;
|
|
214
|
+
readonly curlyUnderline: Style;
|
|
215
|
+
readonly doubleUnderline: Style;
|
|
216
|
+
readonly overline: Style;
|
|
217
|
+
readonly color: Style;
|
|
218
|
+
readonly bgColor: Style;
|
|
219
|
+
readonly font: Style;
|
|
220
|
+
readonly decorationColor: Style;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/** Bright color namespace — provides bright standard colors and RGB methods. */
|
|
224
|
+
readonly bright: {
|
|
225
|
+
/** Returns the bright namespace (self-reference). */
|
|
226
|
+
readonly bright: Style['bright'];
|
|
227
|
+
/** Returns the dark namespace. */
|
|
228
|
+
readonly dark: Style['bright'];
|
|
229
|
+
readonly black: Style;
|
|
230
|
+
readonly red: Style;
|
|
231
|
+
readonly green: Style;
|
|
232
|
+
readonly yellow: Style;
|
|
233
|
+
readonly blue: Style;
|
|
234
|
+
readonly magenta: Style;
|
|
235
|
+
readonly cyan: Style;
|
|
236
|
+
readonly white: Style;
|
|
237
|
+
readonly brightBlack: Style;
|
|
238
|
+
readonly brightRed: Style;
|
|
239
|
+
readonly brightGreen: Style;
|
|
240
|
+
readonly brightYellow: Style;
|
|
241
|
+
readonly brightBlue: Style;
|
|
242
|
+
readonly brightMagenta: Style;
|
|
243
|
+
readonly brightCyan: Style;
|
|
244
|
+
readonly brightWhite: Style;
|
|
245
|
+
readonly darkBlack: Style;
|
|
246
|
+
readonly darkRed: Style;
|
|
247
|
+
readonly darkGreen: Style;
|
|
248
|
+
readonly darkYellow: Style;
|
|
249
|
+
readonly darkBlue: Style;
|
|
250
|
+
readonly darkMagenta: Style;
|
|
251
|
+
readonly darkCyan: Style;
|
|
252
|
+
readonly darkWhite: Style;
|
|
253
|
+
stdRgb(r: number, g: number, b: number): Style;
|
|
254
|
+
brightStdRgb(r: number, g: number, b: number): Style;
|
|
255
|
+
darkStdRgb(r: number, g: number, b: number): Style;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/** Dark (standard) color namespace — mirrors bright namespace structure. */
|
|
259
|
+
readonly dark: Style['bright'];
|
|
260
|
+
|
|
261
|
+
// SGR command getters
|
|
262
|
+
readonly resetAll: Style;
|
|
263
|
+
readonly resetBold: Style;
|
|
264
|
+
readonly resetDim: Style;
|
|
265
|
+
readonly bold: Style;
|
|
266
|
+
readonly dim: Style;
|
|
267
|
+
readonly italic: Style;
|
|
268
|
+
readonly underline: Style;
|
|
269
|
+
readonly blink: Style;
|
|
270
|
+
readonly rapidBlink: Style;
|
|
271
|
+
readonly inverse: Style;
|
|
272
|
+
readonly hidden: Style;
|
|
273
|
+
readonly strikethrough: Style;
|
|
274
|
+
readonly overline: Style;
|
|
275
|
+
readonly defaultFont: Style;
|
|
276
|
+
readonly resetFont: Style;
|
|
277
|
+
readonly fontGothic: Style;
|
|
278
|
+
readonly resetItalic: Style;
|
|
279
|
+
readonly resetUnderline: Style;
|
|
280
|
+
readonly resetBlink: Style;
|
|
281
|
+
readonly resetRapidBlink: Style;
|
|
282
|
+
readonly resetInverse: Style;
|
|
283
|
+
readonly resetHidden: Style;
|
|
284
|
+
readonly resetStrikethrough: Style;
|
|
285
|
+
readonly curlyUnderline: Style;
|
|
286
|
+
readonly resetCurlyUnderline: Style;
|
|
287
|
+
readonly doubleUnderline: Style;
|
|
288
|
+
readonly resetDoubleUnderline: Style;
|
|
289
|
+
readonly defaultColor: Style;
|
|
290
|
+
readonly bgDefaultColor: Style;
|
|
291
|
+
readonly resetColor: Style;
|
|
292
|
+
readonly resetBgColor: Style;
|
|
293
|
+
readonly resetOverline: Style;
|
|
294
|
+
readonly decorationDefaultColor: Style;
|
|
295
|
+
readonly resetDecorationColor: Style;
|
|
296
|
+
|
|
297
|
+
// standard color getters
|
|
298
|
+
readonly black: Style;
|
|
299
|
+
readonly red: Style;
|
|
300
|
+
readonly green: Style;
|
|
301
|
+
readonly yellow: Style;
|
|
302
|
+
readonly blue: Style;
|
|
303
|
+
readonly magenta: Style;
|
|
304
|
+
readonly cyan: Style;
|
|
305
|
+
readonly white: Style;
|
|
306
|
+
readonly brightBlack: Style;
|
|
307
|
+
readonly brightRed: Style;
|
|
308
|
+
readonly brightGreen: Style;
|
|
309
|
+
readonly brightYellow: Style;
|
|
310
|
+
readonly brightBlue: Style;
|
|
311
|
+
readonly brightMagenta: Style;
|
|
312
|
+
readonly brightCyan: Style;
|
|
313
|
+
readonly brightWhite: Style;
|
|
314
|
+
readonly darkBlack: Style;
|
|
315
|
+
readonly darkRed: Style;
|
|
316
|
+
readonly darkGreen: Style;
|
|
317
|
+
readonly darkYellow: Style;
|
|
318
|
+
readonly darkBlue: Style;
|
|
319
|
+
readonly darkMagenta: Style;
|
|
320
|
+
readonly darkCyan: Style;
|
|
321
|
+
readonly darkWhite: Style;
|
|
322
|
+
readonly bgBlack: Style;
|
|
323
|
+
readonly bgRed: Style;
|
|
324
|
+
readonly bgGreen: Style;
|
|
325
|
+
readonly bgYellow: Style;
|
|
326
|
+
readonly bgBlue: Style;
|
|
327
|
+
readonly bgMagenta: Style;
|
|
328
|
+
readonly bgCyan: Style;
|
|
329
|
+
readonly bgWhite: Style;
|
|
330
|
+
readonly bgBrightBlack: Style;
|
|
331
|
+
readonly bgBrightRed: Style;
|
|
332
|
+
readonly bgBrightGreen: Style;
|
|
333
|
+
readonly bgBrightYellow: Style;
|
|
334
|
+
readonly bgBrightBlue: Style;
|
|
335
|
+
readonly bgBrightMagenta: Style;
|
|
336
|
+
readonly bgBrightCyan: Style;
|
|
337
|
+
readonly bgBrightWhite: Style;
|
|
338
|
+
readonly bgDarkBlack: Style;
|
|
339
|
+
readonly bgDarkRed: Style;
|
|
340
|
+
readonly bgDarkGreen: Style;
|
|
341
|
+
readonly bgDarkYellow: Style;
|
|
342
|
+
readonly bgDarkBlue: Style;
|
|
343
|
+
readonly bgDarkMagenta: Style;
|
|
344
|
+
readonly bgDarkCyan: Style;
|
|
345
|
+
readonly bgDarkWhite: Style;
|
|
346
|
+
readonly gray: Style;
|
|
347
|
+
readonly grey: Style;
|
|
348
|
+
readonly bgGray: Style;
|
|
349
|
+
readonly bgGrey: Style;
|
|
350
|
+
|
|
351
|
+
// fg color methods
|
|
352
|
+
stdRgb(r: number, g: number, b: number): Style;
|
|
353
|
+
brightStdRgb(r: number, g: number, b: number): Style;
|
|
354
|
+
color(c: number): Style;
|
|
355
|
+
rgb256(r: number, g: number, b: number): Style;
|
|
356
|
+
hex256(hex: number): Style;
|
|
357
|
+
rgb6(r: number, g: number, b: number): Style;
|
|
358
|
+
grayscale256(i: number): Style;
|
|
359
|
+
grayscale24(i: number): Style;
|
|
360
|
+
trueColor(r: number, g: number, b: number): Style;
|
|
361
|
+
trueGrayscale(i: number): Style;
|
|
362
|
+
hexTrueColor(hex: number): Style;
|
|
363
|
+
rgb(r: number, g: number, b: number): Style;
|
|
364
|
+
grayscale(i: number): Style;
|
|
365
|
+
hex(hex: number): Style;
|
|
366
|
+
greyscale(i: number): Style;
|
|
367
|
+
greyscale24(i: number): Style;
|
|
368
|
+
greyscale256(i: number): Style;
|
|
369
|
+
trueGreyscale(i: number): Style;
|
|
370
|
+
|
|
371
|
+
// bg color methods
|
|
372
|
+
bgStdRgb(r: number, g: number, b: number): Style;
|
|
373
|
+
bgBrightStdRgb(r: number, g: number, b: number): Style;
|
|
374
|
+
bgColor(c: number): Style;
|
|
375
|
+
bgRgb256(r: number, g: number, b: number): Style;
|
|
376
|
+
bgHex256(hex: number): Style;
|
|
377
|
+
bgRgb6(r: number, g: number, b: number): Style;
|
|
378
|
+
bgGrayscale256(i: number): Style;
|
|
379
|
+
bgGrayscale24(i: number): Style;
|
|
380
|
+
bgTrueColor(r: number, g: number, b: number): Style;
|
|
381
|
+
bgTrueGrayscale(i: number): Style;
|
|
382
|
+
bgHexTrueColor(hex: number): Style;
|
|
383
|
+
bgRgb(r: number, g: number, b: number): Style;
|
|
384
|
+
bgGrayscale(i: number): Style;
|
|
385
|
+
bgHex(hex: number): Style;
|
|
386
|
+
bgGreyscale(i: number): Style;
|
|
387
|
+
bgGreyscale24(i: number): Style;
|
|
388
|
+
bgGreyscale256(i: number): Style;
|
|
389
|
+
bgTrueGreyscale(i: number): Style;
|
|
390
|
+
|
|
391
|
+
// decoration color methods
|
|
392
|
+
decorationStdRgb256(r: number, g: number, b: number): Style;
|
|
393
|
+
decorationBrightStdRgb256(r: number, g: number, b: number): Style;
|
|
394
|
+
decorationColor(c: number): Style;
|
|
395
|
+
decorationRgb256(r: number, g: number, b: number): Style;
|
|
396
|
+
decorationHex256(hex: number): Style;
|
|
397
|
+
decorationRgb6(r: number, g: number, b: number): Style;
|
|
398
|
+
decorationGrayscale256(i: number): Style;
|
|
399
|
+
decorationGrayscale24(i: number): Style;
|
|
400
|
+
decorationTrueColor(r: number, g: number, b: number): Style;
|
|
401
|
+
decorationTrueGrayscale(i: number): Style;
|
|
402
|
+
decorationHexTrueColor(hex: number): Style;
|
|
403
|
+
decorationRgb(r: number, g: number, b: number): Style;
|
|
404
|
+
decorationGrayscale(i: number): Style;
|
|
405
|
+
decorationHex(hex: number): Style;
|
|
406
|
+
decorationGreyscale(i: number): Style;
|
|
407
|
+
decorationGreyscale24(i: number): Style;
|
|
408
|
+
decorationGreyscale256(i: number): Style;
|
|
409
|
+
decorationTrueGreyscale(i: number): Style;
|
|
410
|
+
|
|
411
|
+
/** Wraps a string with SGR escape sequences for the current style.
|
|
412
|
+
* @param s - The string to wrap.
|
|
413
|
+
* @returns The styled string.
|
|
414
|
+
*/
|
|
415
|
+
text(s: string): string;
|
|
416
|
+
/** Wraps an array of strings with SGR escape sequences for the current style.
|
|
417
|
+
* @param s - The strings to wrap.
|
|
418
|
+
* @returns The styled strings.
|
|
419
|
+
*/
|
|
420
|
+
text(s: string[]): string[];
|
|
421
|
+
/** Converts the style to an SGR escape sequence string.
|
|
422
|
+
* @returns The SGR escape sequence.
|
|
423
|
+
*/
|
|
424
|
+
toString(): string;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Configuration for the `s` and `c` tagged template literal functions. */
|
|
428
|
+
interface BqStates {
|
|
429
|
+
/** Initial SGR state for the template. */
|
|
430
|
+
initState?: SgrState | string | null;
|
|
431
|
+
/** SGR state to set before processing. */
|
|
432
|
+
setState?: SgrState | string | null;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Tagged template literal function for styled text. Can be called directly or configured with states first. */
|
|
436
|
+
type BqFunction = {
|
|
437
|
+
/** Direct tagged template usage.
|
|
438
|
+
* @param strings - Template string parts.
|
|
439
|
+
* @param args - Interpolated values.
|
|
440
|
+
* @returns The styled string.
|
|
441
|
+
*/
|
|
442
|
+
(strings: TemplateStringsArray, ...args: unknown[]): string;
|
|
443
|
+
/** Configured usage — returns a tagged template function with the given states.
|
|
444
|
+
* @param states - Initial and current SGR state configuration.
|
|
445
|
+
* @returns A tagged template function.
|
|
446
|
+
*/
|
|
447
|
+
(states: BqStates): (strings: TemplateStringsArray, ...args: unknown[]) => string;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
/** Tagged template literal for styled text. Style changes persist after the string.
|
|
451
|
+
* Can also be called as `s({initState, setState})` to create a configured tagger.
|
|
452
|
+
*/
|
|
453
|
+
export const s: BqFunction;
|
|
454
|
+
/** Tagged template literal for styled text. Automatically resets the style at the end.
|
|
455
|
+
* Can also be called as `c({initState, setState})` to create a configured tagger.
|
|
456
|
+
*/
|
|
457
|
+
export const c: BqFunction;
|
|
458
|
+
|
|
459
|
+
/** The default Style singleton with an empty initial state. */
|
|
460
|
+
export const style: Style;
|
|
461
|
+
|
|
462
|
+
export default style;
|