@peteanderson/ansi 1.0.0 → 2.0.0
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/LICENSE +7 -0
- package/README.md +194 -0
- package/dist/ansi.d.ts +79 -41
- package/dist/ansi.d.ts.map +1 -1
- package/dist/ansi.js +9 -6
- package/dist/ansi.js.map +1 -1
- package/dist/features/build.d.ts.map +1 -1
- package/dist/features/build.js.map +1 -1
- package/dist/features/detect.d.ts.map +1 -1
- package/dist/features/detect.js.map +1 -1
- package/dist/features/features.d.ts +1 -3
- package/dist/features/features.d.ts.map +1 -1
- package/dist/features/features.js +12 -13
- package/dist/features/features.js.map +1 -1
- package/dist/features/index.d.ts +1 -0
- package/dist/features/index.d.ts.map +1 -1
- package/dist/features/types.d.ts +2 -0
- package/dist/features/types.d.ts.map +1 -1
- package/dist/pad.d.ts +10 -0
- package/dist/pad.d.ts.map +1 -1
- package/dist/pad.js +8 -0
- package/dist/pad.js.map +1 -1
- package/dist/sgr/color/channel.d.ts +4 -0
- package/dist/sgr/color/channel.d.ts.map +1 -0
- package/dist/sgr/color/channel.js +33 -0
- package/dist/sgr/color/channel.js.map +1 -0
- package/dist/sgr/color/color.d.ts +3 -4
- package/dist/sgr/color/color.d.ts.map +1 -1
- package/dist/sgr/color/color.js +16 -65
- package/dist/sgr/color/color.js.map +1 -1
- package/dist/sgr/color/context.d.ts +13 -0
- package/dist/sgr/color/context.d.ts.map +1 -0
- package/dist/sgr/color/context.js +24 -0
- package/dist/sgr/color/context.js.map +1 -0
- package/dist/sgr/color/rgb.d.ts +5 -0
- package/dist/sgr/color/rgb.d.ts.map +1 -0
- package/dist/sgr/color/rgb.js +32 -0
- package/dist/sgr/color/rgb.js.map +1 -0
- package/dist/sgr/color/utils.d.ts.map +1 -1
- package/dist/sgr/color/utils.js +12 -4
- package/dist/sgr/color/utils.js.map +1 -1
- package/dist/sgr/combine.d.ts +3 -0
- package/dist/sgr/combine.d.ts.map +1 -0
- package/dist/sgr/combine.js +14 -0
- package/dist/sgr/combine.js.map +1 -0
- package/dist/sgr/format-builder.d.ts +3 -0
- package/dist/sgr/format-builder.d.ts.map +1 -0
- package/dist/sgr/format-builder.js +33 -0
- package/dist/sgr/format-builder.js.map +1 -0
- package/dist/sgr/index.d.ts +2 -3
- package/dist/sgr/index.d.ts.map +1 -1
- package/dist/sgr/index.js +1 -3
- package/dist/sgr/index.js.map +1 -1
- package/dist/sgr/lazy.d.ts +6 -0
- package/dist/sgr/lazy.d.ts.map +1 -0
- package/dist/sgr/lazy.js +17 -0
- package/dist/sgr/lazy.js.map +1 -0
- package/dist/sgr/sgr.d.ts +3 -14
- package/dist/sgr/sgr.d.ts.map +1 -1
- package/dist/sgr/sgr.js +44 -37
- package/dist/sgr/sgr.js.map +1 -1
- package/dist/sgr/style.d.ts +2 -14
- package/dist/sgr/style.d.ts.map +1 -1
- package/dist/sgr/style.js +27 -16
- package/dist/sgr/style.js.map +1 -1
- package/dist/sgr/types.d.ts +59 -0
- package/dist/sgr/types.d.ts.map +1 -0
- package/dist/sgr/{color/types.js.map → types.js.map} +1 -1
- package/dist/simplify/atom.d.ts.map +1 -1
- package/dist/simplify/atom.js +8 -1
- package/dist/simplify/atom.js.map +1 -1
- package/dist/simplify/simplify.d.ts +1 -0
- package/dist/simplify/simplify.d.ts.map +1 -1
- package/dist/slice.d.ts +1 -0
- package/dist/slice.d.ts.map +1 -1
- package/dist/slice.js +1 -0
- package/dist/slice.js.map +1 -1
- package/dist/strip.d.ts +6 -0
- package/dist/strip.d.ts.map +1 -1
- package/dist/strip.js +3 -0
- package/dist/strip.js.map +1 -1
- package/dist/typed-object.d.ts +16 -0
- package/dist/typed-object.d.ts.map +1 -0
- package/dist/typed-object.js +36 -0
- package/dist/typed-object.js.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -10
- package/src/ansi.ts +11 -36
- package/src/features/build.ts +4 -3
- package/src/features/detect.ts +6 -3
- package/src/features/features.ts +19 -30
- package/src/features/index.ts +2 -0
- package/src/features/types.ts +9 -0
- package/src/pad.ts +12 -1
- package/src/sgr/color/channel.ts +44 -0
- package/src/sgr/color/color.ts +30 -95
- package/src/sgr/color/context.ts +44 -0
- package/src/sgr/color/index.ts +1 -1
- package/src/sgr/color/rgb.ts +48 -0
- package/src/sgr/color/utils.ts +13 -4
- package/src/sgr/combine.ts +13 -0
- package/src/sgr/format-builder.ts +47 -0
- package/src/sgr/index.ts +3 -3
- package/src/sgr/lazy.ts +21 -0
- package/src/sgr/sgr.ts +61 -57
- package/src/sgr/style.ts +35 -18
- package/src/sgr/types.ts +91 -0
- package/src/simplify/atom.ts +8 -2
- package/src/simplify/simplify.ts +3 -1
- package/src/slice.ts +4 -1
- package/src/strip.ts +10 -1
- package/src/typed-object.ts +85 -0
- package/src/types.ts +28 -0
- package/src/utility-types.d.ts +18 -0
- package/dist/sgr/color/test-rgb.d.ts +0 -3
- package/dist/sgr/color/test-rgb.d.ts.map +0 -1
- package/dist/sgr/color/test-rgb.js +0 -149
- package/dist/sgr/color/test-rgb.js.map +0 -1
- package/dist/sgr/color/types.d.ts +0 -30
- package/dist/sgr/color/types.d.ts.map +0 -1
- package/dist/sgr/utils.d.ts +0 -3
- package/dist/sgr/utils.d.ts.map +0 -1
- package/dist/sgr/utils.js +0 -16
- package/dist/sgr/utils.js.map +0 -1
- package/dist/simplify/test.d.ts +0 -2
- package/dist/simplify/test.d.ts.map +0 -1
- package/dist/simplify/test.js +0 -64
- package/dist/simplify/test.js.map +0 -1
- package/src/sgr/color/types.ts +0 -32
- package/src/sgr/utils.ts +0 -17
- /package/dist/sgr/{color/types.js → types.js} +0 -0
package/dist/sgr/style.js
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeStyle = makeStyle;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const typed_object_1 = require("../typed-object");
|
|
5
|
+
const lazy_1 = require("./lazy");
|
|
6
|
+
const propParams = typed_object_1.TypedObject.entries({
|
|
7
|
+
bold: [1, 22, true],
|
|
8
|
+
dim: [2, 22, true],
|
|
9
|
+
italic: [3, 23],
|
|
10
|
+
underline: [4, 24],
|
|
11
|
+
inverse: [7, 27],
|
|
12
|
+
hidden: [8, 28],
|
|
13
|
+
strikethrough: [9, 29],
|
|
14
|
+
doubleUnderline: [21, 24],
|
|
15
|
+
frame: [51, 54],
|
|
16
|
+
encircle: [52, 54],
|
|
17
|
+
overline: [53, 55],
|
|
18
|
+
});
|
|
19
|
+
function makeStyle(keys, makeFormatter, enabled) {
|
|
20
|
+
const rtn = {};
|
|
21
|
+
for (const [key, args] of propParams) {
|
|
22
|
+
if (keys.has(key)) {
|
|
23
|
+
lazy_1.lazy.add(rtn, key, () => {
|
|
24
|
+
const newKeys = new Set(keys);
|
|
25
|
+
newKeys.delete(key);
|
|
26
|
+
return enabled ? makeFormatter(newKeys, ...args) : makeFormatter(newKeys, 0, 0);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return rtn;
|
|
20
31
|
}
|
|
21
32
|
//# sourceMappingURL=style.js.map
|
package/dist/sgr/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sourceRoot":"","sources":["../../src/sgr/style.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"","sources":["../../src/sgr/style.ts"],"names":[],"mappings":";;AAmBA,8BAkBC;AArCD,kDAA4C;AAC5C,iCAAmC;AAInC,MAAM,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IAED,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type ColorKey = "fg" | "bg";
|
|
2
|
+
export type StyleKey = "bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "doubleUnderline" | "frame" | "encircle" | "overline";
|
|
3
|
+
export type ChainKey = ColorKey | StyleKey;
|
|
4
|
+
export type Chain<Keys extends ChainKey> = Color<Keys> & Style<Keys>;
|
|
5
|
+
export type ChainBuilder = <Keys extends ChainKey>(keys: ReadonlySet<Keys>, baseFormat: FormatBase) => Chain<Keys>;
|
|
6
|
+
export type Code = number | number[];
|
|
7
|
+
export interface FormatBase {
|
|
8
|
+
(text: string): string;
|
|
9
|
+
open: string;
|
|
10
|
+
close: string;
|
|
11
|
+
codes: {
|
|
12
|
+
open: Code;
|
|
13
|
+
close: Code;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface ChainedFormat<Keys extends ChainKey = ChainKey> extends FormatBase {
|
|
17
|
+
and: Chain<Keys>;
|
|
18
|
+
}
|
|
19
|
+
export type Format<Keys extends ChainKey = ChainKey> = [
|
|
20
|
+
Keys
|
|
21
|
+
] extends [never] ? FormatBase : ChainedFormat<Keys>;
|
|
22
|
+
export type FormatBuilder = <Keys extends ChainKey = ChainKey>(keys: ReadonlySet<Keys>, open: Code, close: Code, reset?: boolean) => Format<Keys>;
|
|
23
|
+
export interface Channel<Keys extends ChainKey = ChainKey> {
|
|
24
|
+
black: Format<Keys>;
|
|
25
|
+
red: Format<Keys>;
|
|
26
|
+
green: Format<Keys>;
|
|
27
|
+
yellow: Format<Keys>;
|
|
28
|
+
blue: Format<Keys>;
|
|
29
|
+
magenta: Format<Keys>;
|
|
30
|
+
cyan: Format<Keys>;
|
|
31
|
+
white: Format<Keys>;
|
|
32
|
+
brightBlack: Format<Keys>;
|
|
33
|
+
brightRed: Format<Keys>;
|
|
34
|
+
brightGreen: Format<Keys>;
|
|
35
|
+
brightYellow: Format<Keys>;
|
|
36
|
+
brightBlue: Format<Keys>;
|
|
37
|
+
brightMagenta: Format<Keys>;
|
|
38
|
+
brightCyan: Format<Keys>;
|
|
39
|
+
brightWhite: Format<Keys>;
|
|
40
|
+
rgb: (r: number, g: number, b: number) => Format<Keys>;
|
|
41
|
+
x256: {
|
|
42
|
+
(code: number): Format<Keys>;
|
|
43
|
+
(r: number, g: number, b: number): Format<Keys>;
|
|
44
|
+
};
|
|
45
|
+
default: string;
|
|
46
|
+
}
|
|
47
|
+
export type Color<Keys extends ChainKey = ChainKey> = {
|
|
48
|
+
[K in Extract<ColorKey, Keys>]: Channel<Exclude<Keys, K>>;
|
|
49
|
+
};
|
|
50
|
+
export type Style<Keys extends ChainKey = ChainKey> = {
|
|
51
|
+
[K in Extract<StyleKey, Keys>]: Format<Exclude<Keys, K>>;
|
|
52
|
+
};
|
|
53
|
+
export interface SGR {
|
|
54
|
+
fg: Channel<Exclude<ChainKey, "fg">>;
|
|
55
|
+
bg: Channel<Exclude<ChainKey, "bg">>;
|
|
56
|
+
style: Style;
|
|
57
|
+
reset: string;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sgr/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnC,MAAM,MAAM,QAAQ,GACjB,MAAM,GACN,KAAK,GACL,QAAQ,GACR,WAAW,GACX,SAAS,GACT,QAAQ,GACR,eAAe,GACf,iBAAiB,GACjB,OAAO,GACP,UAAU,GACV,UAAU,CAAC;AAEd,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE3C,MAAM,MAAM,KAAK,CAAC,IAAI,SAAS,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM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AC,QAAQ,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,WAAW,GAAG;IACnB,EAAE,EAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IACzC,EAAE,EAAM,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IACzC,KAAK,EAAG,KAAK,CAAC;IACd,KAAK,EAAG,MAAM,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sgr/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../../src/simplify/atom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"atom.d.ts","sourceRoot":"","sources":["../../src/simplify/atom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAEvC,eAAO,MAAM,sBAAsB,EAAE,SAapC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,SAoBhC,CAAC"}
|
package/dist/simplify/atom.js
CHANGED
|
@@ -21,10 +21,17 @@ const buildIntensityAtom = (attribute, codes, index, state) => {
|
|
|
21
21
|
if (code === 22)
|
|
22
22
|
return { attribute, code: [code] };
|
|
23
23
|
const current = state.get("intensity");
|
|
24
|
-
if (
|
|
24
|
+
if (
|
|
25
|
+
// If there is no intensity currently in the state, then we can just set the new state.
|
|
26
|
+
!current ||
|
|
27
|
+
// If the current intensity is normal (22), then we can just set the new state.
|
|
28
|
+
// Note that while the ultimate transition may return a code sequence of `[22, 1]` or
|
|
29
|
+
// `[22, 2]`, in our state representation, the only two-code intensity is `[1, 2]`.
|
|
25
30
|
current[0] === 22 ||
|
|
31
|
+
// If the current intensity is equal to the new intensity, then return the same state.
|
|
26
32
|
current.length === 1 && current[0] === code)
|
|
27
33
|
return { attribute, code: [code] };
|
|
34
|
+
// Otherwise, we need to set both intensity codes.
|
|
28
35
|
return { attribute, code: [1, 2] };
|
|
29
36
|
};
|
|
30
37
|
exports.buildIntensityAtom = buildIntensityAtom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atom.js","sourceRoot":"","sources":["../../src/simplify/atom.ts"],"names":[],"mappings":";;;AAEO,MAAM,sBAAsB,GAAc,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;IAC5E,QAAQ,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;QAC1B,KAAK,CAAC;YACL,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM;gBAC5B,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,EAAC,CAAC;YAC9E,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAC,CAAC;QAClE,KAAK,CAAC;YACL,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM;gBAC5B,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,EAAC,CAAC;YAC9E,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAC,CAAC;QAClE;YACC,OAAO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":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAuB7C"}
|
|
1
|
+
{"version":3,"file":"simplify.d.ts","sourceRoot":"","sources":["../../src/simplify/simplify.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAuB7C;AAED,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC"}
|
package/dist/slice.d.ts
CHANGED
package/dist/slice.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"slice.d.ts","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":"AAqCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA6BtE;AAED,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC"}
|
package/dist/slice.js
CHANGED
|
@@ -64,6 +64,7 @@ function slice(text, start, end) {
|
|
|
64
64
|
const endIndex = startIndex < text.length && visibleSkipped < end
|
|
65
65
|
? scanCSI(text, startIndex, end - visibleSkipped).index
|
|
66
66
|
: text.length;
|
|
67
|
+
// Start and end the string in the same terminal state it would be in if the string weren't sliced.
|
|
67
68
|
const leadingSequences = skippedSequences(text, 0, startIndex);
|
|
68
69
|
const trailingSequences = skippedSequences(text, endIndex);
|
|
69
70
|
return leadingSequences + text.slice(startIndex, endIndex) + trailingSequences;
|
package/dist/slice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":";;AAwDA,
|
|
1
|
+
{"version":3,"file":"slice.js","sourceRoot":"","sources":["../src/slice.ts"],"names":[],"mappings":";;AAwDA,sBA6BC;AArFD,yCAAyC;AACzC,yCAAyC;AACzC,mCAAsC;AAEtC,SAAS,OAAO,CACf,IAAwB,EACxB,eAAwB,EACxB,YAAwB;IAExB,gEAAgE;IAChE,MAAM,EAAE,GAAG,IAAI,MAAM,CAAC,gBAAK,CAAC,CAAC;IAE7B,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,KAAK,GAAI,eAAe,CAAC;IAE7B,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,IAAI,MAAM,GAAG,YAAY,EAAE,CAAC;QACrD,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,MAAM,EAAE,CAAC;YAC5B,EAAE,CAAC,SAAS,GAAG,KAAK,CAAC;YACrB,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,IAAI,KAAK,EAAE,KAAK,KAAK,KAAK,EAAE,CAAC;gBAC5B,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBACzB,SAAS;YACV,CAAC;QACF,CAAC;QAED,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;IACV,CAAC;IAED,OAAO,EAAC,KAAK,EAAE,MAAM,EAAC,CAAC;AACxB,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa,EAAE,GAAY;IAClE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,gBAAK,CAAC,CAAC,CAAC;IAClE,OAAO,SAAS,CAAC,CAAC,CAAC,IAAA,mBAAQ,EAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,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AAC;IAChE,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE3D,OAAO,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,iBAAiB,CAAC;AAChF,CAAC"}
|
package/dist/strip.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
/** Remove all ANSI escape codes from the given text. */
|
|
1
2
|
export declare const strip: (text: string) => string;
|
|
3
|
+
/** Calculate the visible length of a string with ANSI escape codes stripped. */
|
|
2
4
|
export declare const visibleLength: (text: string) => number;
|
|
5
|
+
/** Remove all ANSI escape codes except SGR codes (m), which are used for color and styling. */
|
|
3
6
|
export declare const sanitize: (text: string) => string;
|
|
7
|
+
export type Strip = typeof strip;
|
|
8
|
+
export type VisibleLength = typeof visibleLength;
|
|
9
|
+
export type Sanitize = typeof sanitize;
|
|
4
10
|
//# sourceMappingURL=strip.d.ts.map
|
package/dist/strip.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,GAAY,MAAM,MAAM,KAAG,MAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAEA,wDAAwD;AACxD,eAAO,MAAM,KAAK,GAAY,MAAM,MAAM,KAAG,MAA6C,CAAC;AAE3F,gFAAgF;AAChF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAA4B,CAAC;AAE1E,+FAA+F;AAC/F,eAAO,MAAM,QAAQ,GAAS,MAAM,MAAM,KAAG,MAAgD,CAAC;AAE9F,MAAM,MAAM,KAAK,GAAW,OAAO,KAAK,CAAC;AACzC,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC;AACjD,MAAM,MAAM,QAAQ,GAAQ,OAAO,QAAQ,CAAC"}
|
package/dist/strip.js
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sanitize = exports.visibleLength = exports.strip = void 0;
|
|
4
4
|
const patterns_1 = require("./patterns");
|
|
5
|
+
/** Remove all ANSI escape codes from the given text. */
|
|
5
6
|
const strip = (text) => text.replace(new RegExp(patterns_1.rxCSI), "");
|
|
6
7
|
exports.strip = strip;
|
|
8
|
+
/** Calculate the visible length of a string with ANSI escape codes stripped. */
|
|
7
9
|
const visibleLength = (text) => (0, exports.strip)(text).length;
|
|
8
10
|
exports.visibleLength = visibleLength;
|
|
11
|
+
/** Remove all ANSI escape codes except SGR codes (m), which are used for color and styling. */
|
|
9
12
|
const sanitize = (text) => text.replace(new RegExp(patterns_1.rxUnsafe), "");
|
|
10
13
|
exports.sanitize = sanitize;
|
|
11
14
|
//# sourceMappingURL=strip.js.map
|
package/dist/strip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;
|
|
1
|
+
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAE3C,wDAAwD;AACjD,MAAM,KAAK,GAAW,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,gBAAK,CAAC,EAAE,EAAE,CAAC,CAAC;AAA9E,QAAA,KAAK,SAAyE;AAE3F,gFAAgF;AACzE,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AAA7D,QAAA,aAAa,iBAAgD;AAE1E,+FAA+F;AACxF,MAAM,QAAQ,GAAQ,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,mBAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;AAAjF,QAAA,QAAQ,YAAyE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type TypedPropertyDescriptorMap<T> = {
|
|
2
|
+
[K in keyof T]: TypedPropertyDescriptor<T[K]>;
|
|
3
|
+
};
|
|
4
|
+
export interface TypedObject {
|
|
5
|
+
getOwnPropertyNames<T>(o: T): KeyOf<T>[];
|
|
6
|
+
keys<T>(o: T): KeyOf<T>[];
|
|
7
|
+
values<T>(o: T): ValuesOf<T>;
|
|
8
|
+
entries<T>(o: T): EntriesOf<T>;
|
|
9
|
+
fromEntries<K extends keyof any, V>(entries: Iterable<readonly [K, V]>): Record<K, V>;
|
|
10
|
+
create<T>(prototype: object, properties: TypedPropertyDescriptorMap<T>): T;
|
|
11
|
+
recreate<T, U>(o: T, fn: <K extends keyof T>(key: K, property: TypedPropertyDescriptor<T[K]>) => [K, TypedPropertyDescriptor<U>]): Record<keyof T, U>;
|
|
12
|
+
transform<T, K extends keyof any, V>(o: T, fn: (key: KeyOf<T>, value: T[keyof T]) => readonly [K, V]): Record<K, V>;
|
|
13
|
+
toMap<T extends {}, K = KeyOf<T>, V = T[keyof T]>(o: T, transform?: (key: KeyOf<T>, value: T[keyof T]) => readonly [K, V]): Map<K, V>;
|
|
14
|
+
}
|
|
15
|
+
export declare const TypedObject: TypedObject;
|
|
16
|
+
//# sourceMappingURL=typed-object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-object.d.ts","sourceRoot":"","sources":["../src/typed-object.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,CAAC,CAAC,IAAI;KAC1C,CAAC,IAAI,MAAM,CAAC,GAAG,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,WAAW,WAAW;IAC3B,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,K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C,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAC/C,CAAC,EAAY,CAAC,EACd,SAAS,CAAC,EAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAChE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACb;AACD,eAAO,MAAM,WAAW,EAoDlB,WAAW,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedObject = void 0;
|
|
4
|
+
exports.TypedObject = Object.freeze({
|
|
5
|
+
getOwnPropertyNames: Object.getOwnPropertyNames,
|
|
6
|
+
keys: Object.keys,
|
|
7
|
+
values: Object.values,
|
|
8
|
+
entries: Object.entries,
|
|
9
|
+
fromEntries: Object.fromEntries,
|
|
10
|
+
create: Object.create,
|
|
11
|
+
recreate: (o, fn) => Object.create(Object.getPrototypeOf(o), exports.TypedObject.transform(Object.getOwnPropertyDescriptors(o), fn)),
|
|
12
|
+
transform: (o, fn) => exports.TypedObject.fromEntries(exports.TypedObject.entries(o).map(([key, value]) => fn(key, value))),
|
|
13
|
+
/**
|
|
14
|
+
@type {
|
|
15
|
+
<T extends {}, K = KeyOf<T>, V = T[keyof T]>(
|
|
16
|
+
o : T,
|
|
17
|
+
transform? : (key: KeyOf<T>, value: T[keyof T]) => readonly [K, V]
|
|
18
|
+
) => Map<K, V>
|
|
19
|
+
}
|
|
20
|
+
*/
|
|
21
|
+
toMap(o, transform) {
|
|
22
|
+
const map = new Map();
|
|
23
|
+
if (transform) {
|
|
24
|
+
for (const [key, value] of exports.TypedObject.entries(o)) {
|
|
25
|
+
const [newKey, newValue] = transform(key, value);
|
|
26
|
+
map.set(newKey, newValue);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
for (const [key, value] of exports.TypedObject.entries(o))
|
|
31
|
+
map.set(key, value);
|
|
32
|
+
}
|
|
33
|
+
return map;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=typed-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-object.js","sourceRoot":"","sources":["../src/typed-object.ts"],"names":[],"mappings":";;;AAgCa,QAAA,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,mBAAmB,EAAG,MAAM,CAAC,mBAAmB;IAChD,IAAI,EAAkB,MAAM,CAAC,IAAI;IACjC,MAAM,EAAgB,MAAM,CAAC,MAAM;IACnC,OAAO,EAAe,MAAM,CAAC,OAAO;IACpC,WAAW,EAAW,MAAM,CAAC,WAAW;IACxC,MAAM,EAAgB,MAAM,CAAC,MAAM;IAEnC,QAAQ,EAAE,CACT,CAAM,EACN,EAGoC,EACf,EAAE,CAAC,MAAM,CAAC,MAAM,CACrC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EACxB,mBAAW,CAAC,SAAS,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,EAAS,CAAC,CACrE;IAED,SAAS,EAAE,CACV,CAAM,EACN,EAA0D,EAC3C,EAAE,CAAC,mBAAW,CAAC,WAAW,CACzC,mBAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAU,EAAE,KAAK,CAAC,CAAC,CACnE;IAED;;;;;;;MAOE;IACF,KAAK,CACJ,CAAc,EACd,SAAkE;QAElE,MAAM,GAAG,GAAG,IAAI,GAAG,EAAQ,CAAC;QAE5B,IAAI,SAAS,EAAE,CAAC;YACf,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,mBAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,GAAU,EAAE,KAAK,CAAC,CAAC;gBACxD,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC;aAAM,CAAC;YACP,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,mBAAW,CAAC,OAAO,CAAC,CAAC,CAAC;gBAChD,GAAG,CAAC,GAAG,CAAC,GAAU,EAAE,KAAY,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,GAAG,CAAC;IACZ,CAAC;CACD,CAAgB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Caret } from "./caret";
|
|
2
|
+
import type { Erase } from "./erase";
|
|
3
|
+
import type { Features } from "./features";
|
|
4
|
+
import type { PadEnd, PadStart } from "./pad";
|
|
5
|
+
import type { Scroll } from "./scroll";
|
|
6
|
+
import type { SGR } from "./sgr";
|
|
7
|
+
import type { Simplify } from "./simplify";
|
|
8
|
+
import type { Slice } from "./slice";
|
|
9
|
+
import type { Sanitize, Strip, VisibleLength } from "./strip";
|
|
10
|
+
import type { Terminal } from "./terminal";
|
|
11
|
+
export type Ansi = SGR & {
|
|
12
|
+
caret: Caret;
|
|
13
|
+
erase: Erase;
|
|
14
|
+
scroll: Scroll;
|
|
15
|
+
terminal: Terminal;
|
|
16
|
+
padEnd: PadEnd;
|
|
17
|
+
padStart: PadStart;
|
|
18
|
+
strip: Strip;
|
|
19
|
+
visibleLength: VisibleLength;
|
|
20
|
+
sanitize: Sanitize;
|
|
21
|
+
slice: Slice;
|
|
22
|
+
simplify: Simplify;
|
|
23
|
+
features: Features;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,KAAK,EAAC,MAA+B,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAC,KAAK,EAAC,MAA+B,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAC,QAAQ,EAAC,MAA4B,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAoB,OAAO,CAAC;AAC1D,OAAO,KAAK,EAAC,MAAM,EAAC,MAA8B,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAiC,OAAO,CAAC;AAC1D,OAAO,KAAK,EAAC,QAAQ,EAAC,MAA4B,YAAY,CAAC;AAC/D,OAAO,KAAK,EAAC,KAAK,EAAC,MAA+B,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAC,QAAQ,EAAC,MAA4B,YAAY,CAAC;AAE/D,MAAM,MAAM,IAAI,GAAG,GAAG,GAAG;IACxB,KAAK,EAAM,KAAK,CAAC;IACjB,KAAK,EAAM,KAAK,CAAC;IACjB,MAAM,EAAK,MAAM,CAAC;IAClB,QAAQ,EAAG,QAAQ,CAAC;IAEpB,MAAM,EAAK,MAAM,CAAC;IAClB,QAAQ,EAAG,QAAQ,CAAC;IAEpB,KAAK,EAAW,KAAK,CAAC;IACtB,aAAa,EAAG,aAAa,CAAC;IAC9B,QAAQ,EAAQ,QAAQ,CAAC;IACzB,KAAK,EAAW,KAAK,CAAC;IACtB,QAAQ,EAAQ,QAAQ,CAAC;IAEzB,QAAQ,EAAG,QAAQ,CAAC;CACpB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,22 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name" : "@peteanderson/ansi",
|
|
3
|
-
"version" : "
|
|
3
|
+
"version" : "2.0.0",
|
|
4
4
|
"description" : "ANSI escape sequence generation with automatic feature detection",
|
|
5
|
+
"author" : {
|
|
6
|
+
"name" : "Pete Anderson",
|
|
7
|
+
"email" : "pete.the.anderson@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"repository" : {
|
|
10
|
+
"type" : "git",
|
|
11
|
+
"url" : "git+https://github.com/anderson-pete/ansi.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords" : ["ansi", "nodejs", "color", "terminal", "cli"],
|
|
14
|
+
"engines" : {"node": ">=18"},
|
|
5
15
|
"files" : ["dist", "src"],
|
|
6
|
-
"exports" : {
|
|
7
|
-
".": {
|
|
8
|
-
"require" : "./dist/index.js",
|
|
9
|
-
"types" : "./dist/index.d.ts"
|
|
10
|
-
}},
|
|
11
16
|
"main" : "dist/index.js",
|
|
12
17
|
"types" : "dist/index.d.ts",
|
|
13
|
-
"
|
|
18
|
+
"exports" : {
|
|
19
|
+
".": {
|
|
20
|
+
"types" : "./dist/index.d.ts",
|
|
21
|
+
"require" : "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license" : "MIT",
|
|
14
25
|
"scripts" : {
|
|
15
|
-
"
|
|
16
|
-
"build
|
|
26
|
+
"prebuild" : "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true})\"",
|
|
27
|
+
"build" : "tsc -p tsconfig.build.json",
|
|
28
|
+
"prepack" : "npm run build",
|
|
29
|
+
"tag" : "git tag -a v$npm_package_version -m v$npm_package_version",
|
|
30
|
+
"tag-all" : "tsx --tsconfig scripts/tsconfig.json scripts/tag-all.ts"
|
|
17
31
|
},
|
|
18
32
|
"devDependencies" : {
|
|
19
33
|
"@types/node" : "^26.0.0",
|
|
34
|
+
"tsx" : "^4.22.4",
|
|
20
35
|
"typescript" : "^6.0.3"
|
|
21
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"dependencies" : {"@peteanderson/props": "^2.0.0"}
|
|
22
38
|
}
|
package/src/ansi.ts
CHANGED
|
@@ -3,54 +3,25 @@ import {makeErase} from "./erase";
|
|
|
3
3
|
import {getFeatures} from "./features";
|
|
4
4
|
import {padEnd, padStart} from "./pad";
|
|
5
5
|
import {makeScroll} from "./scroll";
|
|
6
|
-
import {
|
|
6
|
+
import {makeSGR} from "./sgr";
|
|
7
7
|
import {simplify} from "./simplify";
|
|
8
8
|
import {slice} from "./slice";
|
|
9
9
|
import {sanitize, strip, visibleLength} from "./strip";
|
|
10
10
|
import {makeTerminal} from "./terminal";
|
|
11
11
|
|
|
12
|
-
import type {Args}
|
|
13
|
-
import type {
|
|
14
|
-
import type {Erase} from "./erase";
|
|
15
|
-
import type {Features} from "./features/types";
|
|
16
|
-
import type {Scroll} from "./scroll";
|
|
17
|
-
import type {Color, Style} from "./sgr";
|
|
18
|
-
import type {Terminal} from "./terminal";
|
|
12
|
+
import type {Args} from "./features";
|
|
13
|
+
import type {Ansi} from "./types";
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
caret : Caret;
|
|
22
|
-
erase : Erase;
|
|
23
|
-
scroll : Scroll;
|
|
24
|
-
|
|
25
|
-
reset : string;
|
|
26
|
-
style : Style;
|
|
27
|
-
|
|
28
|
-
terminal : Terminal;
|
|
29
|
-
|
|
30
|
-
padEnd : typeof padEnd;
|
|
31
|
-
padStart : typeof padStart;
|
|
32
|
-
|
|
33
|
-
strip : typeof strip;
|
|
34
|
-
visibleLength : typeof visibleLength;
|
|
35
|
-
sanitize : typeof sanitize;
|
|
36
|
-
slice : typeof slice;
|
|
37
|
-
simplify : typeof simplify;
|
|
38
|
-
|
|
39
|
-
features : Features;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export function makeAnsi(...args: Args): Ansi {
|
|
15
|
+
function makeAnsi(...args: Args): Ansi {
|
|
43
16
|
const features = getFeatures(...args);
|
|
44
17
|
|
|
45
18
|
return {
|
|
19
|
+
...makeSGR(features),
|
|
20
|
+
|
|
46
21
|
caret : makeCaret(features.caret),
|
|
47
22
|
erase : makeErase(features.erase),
|
|
48
23
|
scroll : makeScroll(features.scroll),
|
|
49
24
|
|
|
50
|
-
reset : makeReset(features.colorDepth > 1),
|
|
51
|
-
style : makeStyle(features.style),
|
|
52
|
-
...makeColor(features.colorDepth),
|
|
53
|
-
|
|
54
25
|
terminal: makeTerminal(features.terminal),
|
|
55
26
|
|
|
56
27
|
padEnd,
|
|
@@ -66,6 +37,10 @@ export function makeAnsi(...args: Args): Ansi {
|
|
|
66
37
|
};
|
|
67
38
|
}
|
|
68
39
|
|
|
69
|
-
const ansi = Object.assign(makeAnsi, makeAnsi());
|
|
40
|
+
export const ansi = Object.assign(makeAnsi, makeAnsi());
|
|
41
|
+
|
|
42
|
+
export const {fg, bg, style, reset, caret, erase, scroll, terminal} = ansi;
|
|
43
|
+
|
|
44
|
+
export {padEnd, padStart, strip, visibleLength}
|
|
70
45
|
|
|
71
46
|
export default ansi;
|
package/src/features/build.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getColorDepth
|
|
2
|
-
|
|
1
|
+
import {detectFeatureSupport, getColorDepth} from "./detect";
|
|
2
|
+
|
|
3
|
+
import type {ColorDepth, Features} from "./types";
|
|
3
4
|
|
|
4
5
|
function normalizeColorDepth(colorDepth: number): ColorDepth {
|
|
5
6
|
colorDepth = Math.floor(colorDepth);
|
|
@@ -49,4 +50,4 @@ export const tty = (stream: NodeJS.WriteStream): Features =>
|
|
|
49
50
|
build(true, getColorDepth(stream));
|
|
50
51
|
|
|
51
52
|
export const pipe = (): Features =>
|
|
52
|
-
build(false, getColorDepth());
|
|
53
|
+
build(false, getColorDepth());
|
package/src/features/detect.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ColorDepth, Features} from "./types";
|
|
2
2
|
|
|
3
3
|
export function getColorDepth(stream?: NodeJS.WriteStream): ColorDepth {
|
|
4
4
|
if (stream?.isTTY)
|
|
@@ -21,7 +21,10 @@ export function getColorDepth(stream?: NodeJS.WriteStream): ColorDepth {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function detectFeatureSupport(
|
|
24
|
+
export function detectFeatureSupport(
|
|
25
|
+
isTTY : boolean,
|
|
26
|
+
colorDepth : ColorDepth,
|
|
27
|
+
): Omit<Features, "colorDepth"> {
|
|
25
28
|
const enabled = process.env.TERM !== "dumb" && isTTY;
|
|
26
29
|
return {
|
|
27
30
|
style : colorDepth > 1,
|
|
@@ -30,4 +33,4 @@ export function detectFeatureSupport(isTTY: boolean, colorDepth: ColorDepth): Om
|
|
|
30
33
|
scroll : enabled,
|
|
31
34
|
terminal : enabled,
|
|
32
35
|
};
|
|
33
|
-
}
|
|
36
|
+
}
|
package/src/features/features.ts
CHANGED
|
@@ -1,42 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { build,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type Args =
|
|
8
|
-
| [enabled : boolean, stream?: NodeJS.WriteStream]
|
|
9
|
-
| [colorDepth : ColorDepth, stream?: NodeJS.WriteStream]
|
|
10
|
-
| [features : Partial<Features>, stream?: NodeJS.WriteStream]
|
|
11
|
-
| [socket : Socket]
|
|
12
|
-
| [stream? : NodeJS.WriteStream];
|
|
1
|
+
import {Socket} from "node:net";
|
|
2
|
+
import {WriteStream} from "node:tty";
|
|
3
|
+
import {boolean, build, number, pipe, tty} from "./build";
|
|
4
|
+
import {getColorDepth} from "./detect";
|
|
5
|
+
|
|
6
|
+
import type {Args, Features} from "./types";
|
|
13
7
|
|
|
14
8
|
export function getFeatures(...args: Args): Features {
|
|
15
|
-
|
|
16
|
-
boolean | ColorDepth | Partial<Features> | Socket | NodeJS.WriteStream | undefined,
|
|
17
|
-
NodeJS.WriteStream | undefined,
|
|
18
|
-
];
|
|
9
|
+
let [features, stream] = args;
|
|
19
10
|
|
|
20
|
-
if (typeof
|
|
21
|
-
return boolean((
|
|
11
|
+
if (typeof features === "boolean")
|
|
12
|
+
return boolean((stream ?? process.stdout).isTTY, features);
|
|
22
13
|
|
|
23
|
-
if (typeof
|
|
24
|
-
return number((
|
|
14
|
+
if (typeof features === "number")
|
|
15
|
+
return number((stream ?? process.stdout).isTTY, features);
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
? second ?? process.stdout
|
|
29
|
-
: first;
|
|
17
|
+
if (!features || typeof features !== "object")
|
|
18
|
+
features = (stream ?? process.stdout);
|
|
30
19
|
|
|
31
|
-
if (
|
|
32
|
-
return tty(
|
|
20
|
+
if (features instanceof WriteStream)
|
|
21
|
+
return tty(features);
|
|
33
22
|
|
|
34
|
-
if (
|
|
23
|
+
if (features instanceof Socket)
|
|
35
24
|
return pipe();
|
|
36
25
|
|
|
37
|
-
const {colorDepth, style, caret, erase, scroll, terminal} =
|
|
26
|
+
const {colorDepth, style, caret, erase, scroll, terminal} = features;
|
|
38
27
|
|
|
39
|
-
|
|
28
|
+
stream ??= process.stdout;
|
|
40
29
|
|
|
41
30
|
if (colorDepth)
|
|
42
31
|
build(stream.isTTY, colorDepth, style, caret, erase, scroll, terminal);
|
|
@@ -45,4 +34,4 @@ export function getFeatures(...args: Args): Features {
|
|
|
45
34
|
return build(true, getColorDepth(stream), style, caret, erase, scroll, terminal);
|
|
46
35
|
|
|
47
36
|
return build(false, getColorDepth(), style, caret, erase, scroll, terminal);
|
|
48
|
-
}
|
|
37
|
+
}
|
package/src/features/index.ts
CHANGED
package/src/features/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type {Socket} from "node:net";
|
|
2
|
+
|
|
1
3
|
export type ColorDepth = 1 | 3 | 4 | 8 | 24;
|
|
2
4
|
|
|
3
5
|
export interface Features {
|
|
@@ -8,3 +10,10 @@ export interface Features {
|
|
|
8
10
|
scroll : boolean;
|
|
9
11
|
terminal : boolean;
|
|
10
12
|
}
|
|
13
|
+
|
|
14
|
+
export type Args =
|
|
15
|
+
| [enabled : boolean, stream?: NodeJS.WriteStream]
|
|
16
|
+
| [colorDepth : ColorDepth, stream?: NodeJS.WriteStream]
|
|
17
|
+
| [features : Partial<Features>, stream?: NodeJS.WriteStream]
|
|
18
|
+
| [socket : Socket]
|
|
19
|
+
| [stream? : NodeJS.WriteStream];
|
package/src/pad.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import {visibleLength} from "./strip";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Pad the given text at the end with the specified fill string to the target visible length without
|
|
5
|
+
* counting ANSI escape codes.
|
|
6
|
+
*/
|
|
3
7
|
export const padEnd = (text: string, targetLength: number, fillString = " "): string =>
|
|
4
8
|
text + fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length);
|
|
5
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Pad the given text at the start with the specified fill string to the target visible length
|
|
12
|
+
* without counting ANSI escape codes.
|
|
13
|
+
*/
|
|
6
14
|
export const padStart = (text: string, targetLength: number, fillString = " "): string =>
|
|
7
|
-
fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length) + text;
|
|
15
|
+
fillString.repeat(Math.max(0, targetLength - visibleLength(text)) / fillString.length) + text;
|
|
16
|
+
|
|
17
|
+
export type PadEnd = typeof padEnd;
|
|
18
|
+
export type PadStart = typeof padStart;
|