@elench/testkit 0.1.114 → 0.1.116
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 +33 -8
- package/lib/cli/args.mjs +3 -3
- package/lib/cli/assistant/app.mjs +4 -2
- package/lib/cli/assistant/session.mjs +5 -1
- package/lib/cli/assistant/state.mjs +1 -2
- package/lib/cli/command-flags.mjs +4 -0
- package/lib/cli/commands/db/schema/refresh.mjs +21 -0
- package/lib/cli/commands/db/schema/verify.mjs +27 -0
- package/lib/cli/components/blocks/run-tree.mjs +7 -2
- package/lib/cli/components/hooks/use-element-layout.mjs +63 -0
- package/lib/cli/components/hooks/use-spinner-frame.mjs +26 -0
- package/lib/cli/entrypoint.mjs +1 -0
- package/lib/cli/operations/db/schema/refresh/operation.mjs +56 -0
- package/lib/cli/operations/db/{snapshot/capture → schema/verify}/operation.mjs +6 -27
- package/lib/cli/operations/run/operation.mjs +1 -0
- package/lib/cli/renderers/db-schema/text.mjs +7 -0
- package/lib/config/database.mjs +64 -0
- package/lib/config-api/index.d.ts +16 -1
- package/lib/config-api/index.mjs +31 -16
- package/lib/database/fingerprint.mjs +2 -0
- package/lib/database/index.mjs +142 -104
- package/lib/database/schema-source.mjs +295 -0
- package/lib/database/template-steps.mjs +158 -38
- package/lib/runner/orchestrator.mjs +4 -3
- package/lib/runner/template-steps.mjs +12 -1
- package/lib/runner/template.mjs +16 -1
- package/node_modules/@alcalzone/ansi-tokenize/README.md +0 -5
- package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.d.ts +8 -0
- package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.js +10 -8
- package/node_modules/@alcalzone/ansi-tokenize/build/ansiCodes.js.map +1 -1
- package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.d.ts +1 -5
- package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.js +9 -45
- package/node_modules/@alcalzone/ansi-tokenize/build/tokenize.js.map +1 -1
- package/node_modules/@alcalzone/ansi-tokenize/package.json +1 -1
- package/node_modules/@elench/next-analysis/package.json +1 -1
- package/node_modules/@elench/testkit-bridge/package.json +2 -2
- package/node_modules/@elench/testkit-protocol/package.json +1 -1
- package/node_modules/@elench/ts-analysis/package.json +1 -1
- package/node_modules/cli-boxes/index.d.ts +95 -90
- package/node_modules/cli-boxes/index.js +5 -2
- package/node_modules/cli-boxes/package.json +6 -13
- package/node_modules/cli-boxes/readme.md +15 -3
- package/node_modules/cli-truncate/index.d.ts +1 -1
- package/node_modules/cli-truncate/package.json +4 -4
- package/node_modules/cli-truncate/readme.md +1 -0
- package/node_modules/es-toolkit/CHANGELOG.md +801 -0
- package/node_modules/es-toolkit/src/compat/_internal/Equals.d.ts +1 -0
- package/node_modules/es-toolkit/src/compat/_internal/IsWritable.d.ts +3 -0
- package/node_modules/es-toolkit/src/compat/_internal/MutableList.d.ts +4 -0
- package/node_modules/es-toolkit/src/compat/_internal/RejectReadonly.d.ts +4 -0
- package/node_modules/esprima/ChangeLog +235 -0
- package/node_modules/ink/build/apply-styles.js +175 -0
- package/node_modules/ink/build/build-layout.js +77 -0
- package/node_modules/ink/build/calculate-wrapped-text.js +53 -0
- package/node_modules/ink/build/components/App.d.ts +1 -4
- package/node_modules/ink/build/components/App.js +22 -142
- package/node_modules/ink/build/components/App.js.map +1 -1
- package/node_modules/ink/build/components/AppContext.d.ts +3 -23
- package/node_modules/ink/build/components/AppContext.js +4 -7
- package/node_modules/ink/build/components/AppContext.js.map +1 -1
- package/node_modules/ink/build/components/Box.d.ts +3 -16
- package/node_modules/ink/build/components/Color.js +62 -0
- package/node_modules/ink/build/components/Cursor.d.ts +83 -0
- package/node_modules/ink/build/components/Cursor.js +53 -0
- package/node_modules/ink/build/components/Cursor.js.map +1 -0
- package/node_modules/ink/build/components/ErrorBoundary.d.ts +2 -2
- package/node_modules/ink/build/components/ErrorOverview.js +6 -6
- package/node_modules/ink/build/components/ErrorOverview.js.map +1 -1
- package/node_modules/ink/build/components/Static.js.map +1 -1
- package/node_modules/ink/build/components/StdinContext.d.ts +1 -7
- package/node_modules/ink/build/components/StdinContext.js +0 -1
- package/node_modules/ink/build/components/StdinContext.js.map +1 -1
- package/node_modules/ink/build/components/Text.d.ts +1 -1
- package/node_modules/ink/build/components/Text.js +1 -1
- package/node_modules/ink/build/components/Text.js.map +1 -1
- package/node_modules/ink/build/components/Transform.d.ts +1 -1
- package/node_modules/ink/build/devtools-window-polyfill.js +4 -7
- package/node_modules/ink/build/devtools-window-polyfill.js.map +1 -1
- package/node_modules/ink/build/devtools.js +6 -31
- package/node_modules/ink/build/devtools.js.map +1 -1
- package/node_modules/ink/build/dom.d.ts +1 -5
- package/node_modules/ink/build/dom.js +1 -20
- package/node_modules/ink/build/dom.js.map +1 -1
- package/node_modules/ink/build/experimental/apply-style.js +140 -0
- package/node_modules/ink/build/experimental/dom.js +123 -0
- package/node_modules/ink/build/experimental/output.js +91 -0
- package/node_modules/ink/build/experimental/reconciler.js +141 -0
- package/node_modules/ink/build/experimental/renderer.js +81 -0
- package/node_modules/ink/build/hooks/use-app.d.ts +1 -1
- package/node_modules/ink/build/hooks/use-app.js +1 -1
- package/node_modules/ink/build/hooks/use-cursor.d.ts +1 -1
- package/node_modules/ink/build/hooks/use-cursor.js +1 -1
- package/node_modules/ink/build/hooks/use-focus-manager.d.ts +2 -17
- package/node_modules/ink/build/hooks/use-focus-manager.js +1 -2
- package/node_modules/ink/build/hooks/use-focus-manager.js.map +1 -1
- package/node_modules/ink/build/hooks/use-focus.d.ts +1 -2
- package/node_modules/ink/build/hooks/use-focus.js +4 -5
- package/node_modules/ink/build/hooks/use-focus.js.map +1 -1
- package/node_modules/ink/build/hooks/use-input.d.ts +1 -2
- package/node_modules/ink/build/hooks/use-input.js +80 -82
- package/node_modules/ink/build/hooks/use-input.js.map +1 -1
- package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.d.ts +1 -2
- package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.js +1 -2
- package/node_modules/ink/build/hooks/use-is-screen-reader-enabled.js.map +1 -1
- package/node_modules/ink/build/hooks/use-stderr.d.ts +1 -1
- package/node_modules/ink/build/hooks/use-stderr.js +1 -1
- package/node_modules/ink/build/hooks/use-stdin.d.ts +2 -4
- package/node_modules/ink/build/hooks/use-stdin.js +1 -2
- package/node_modules/ink/build/hooks/use-stdin.js.map +1 -1
- package/node_modules/ink/build/hooks/use-stdout.d.ts +1 -1
- package/node_modules/ink/build/hooks/use-stdout.js +1 -1
- package/node_modules/ink/build/hooks/useInput.js +38 -0
- package/node_modules/ink/build/index.d.ts +1 -8
- package/node_modules/ink/build/index.js +0 -4
- package/node_modules/ink/build/index.js.map +1 -1
- package/node_modules/ink/build/ink.d.ts +3 -48
- package/node_modules/ink/build/ink.js +155 -325
- package/node_modules/ink/build/ink.js.map +1 -1
- package/node_modules/ink/build/input-parser.d.ts +1 -4
- package/node_modules/ink/build/input-parser.js +30 -70
- package/node_modules/ink/build/input-parser.js.map +1 -1
- package/node_modules/ink/build/instance.js +205 -0
- package/node_modules/ink/build/layout.d.ts +7 -0
- package/node_modules/ink/build/layout.js +33 -0
- package/node_modules/ink/build/layout.js.map +1 -0
- package/node_modules/ink/build/log-update.d.ts +0 -1
- package/node_modules/ink/build/log-update.js +1 -13
- package/node_modules/ink/build/log-update.js.map +1 -1
- package/node_modules/ink/build/measure-element.d.ts +0 -4
- package/node_modules/ink/build/measure-element.js +0 -4
- package/node_modules/ink/build/measure-element.js.map +1 -1
- package/node_modules/ink/build/options.d.ts +52 -0
- package/node_modules/ink/build/options.js +2 -0
- package/node_modules/ink/build/options.js.map +1 -0
- package/node_modules/ink/build/output.js +0 -25
- package/node_modules/ink/build/output.js.map +1 -1
- package/node_modules/ink/build/parse-keypress.d.ts +3 -1
- package/node_modules/ink/build/parse-keypress.js +17 -19
- package/node_modules/ink/build/parse-keypress.js.map +1 -1
- package/node_modules/ink/build/reconciler.js +27 -46
- package/node_modules/ink/build/reconciler.js.map +1 -1
- package/node_modules/ink/build/render-border.js +18 -29
- package/node_modules/ink/build/render-border.js.map +1 -1
- package/node_modules/ink/build/render-to-string.js +1 -2
- package/node_modules/ink/build/render-to-string.js.map +1 -1
- package/node_modules/ink/build/render.d.ts +2 -57
- package/node_modules/ink/build/render.js +11 -18
- package/node_modules/ink/build/render.js.map +1 -1
- package/node_modules/ink/build/screen-reader-update.d.ts +13 -0
- package/node_modules/ink/build/screen-reader-update.js +38 -0
- package/node_modules/ink/build/screen-reader-update.js.map +1 -0
- package/node_modules/ink/build/styles.d.ts +16 -78
- package/node_modules/ink/build/styles.js +31 -102
- package/node_modules/ink/build/styles.js.map +1 -1
- package/node_modules/ink/build/utils.d.ts +2 -9
- package/node_modules/ink/build/utils.js +3 -18
- package/node_modules/ink/build/utils.js.map +1 -1
- package/node_modules/ink/build/wrap-text.js +0 -7
- package/node_modules/ink/build/wrap-text.js.map +1 -1
- package/node_modules/ink/build/write-synchronized.d.ts +1 -1
- package/node_modules/ink/build/write-synchronized.js +2 -4
- package/node_modules/ink/build/write-synchronized.js.map +1 -1
- package/node_modules/ink/node_modules/emoji-regex/LICENSE-MIT.txt +20 -0
- package/node_modules/ink/node_modules/emoji-regex/README.md +107 -0
- package/node_modules/ink/node_modules/emoji-regex/index.d.ts +3 -0
- package/node_modules/ink/node_modules/emoji-regex/index.js +4 -0
- package/node_modules/ink/node_modules/emoji-regex/index.mjs +4 -0
- package/node_modules/ink/node_modules/emoji-regex/package.json +45 -0
- package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/index.d.ts +1 -1
- package/node_modules/ink/node_modules/wrap-ansi/index.js +222 -0
- package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/index.js +82 -0
- package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/license +9 -0
- package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/package.json +64 -0
- package/node_modules/ink/node_modules/wrap-ansi/node_modules/string-width/readme.md +66 -0
- package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/package.json +11 -11
- package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/readme.md +0 -2
- package/node_modules/ink/package.json +98 -34
- package/node_modules/ink/readme.md +48 -554
- package/node_modules/slice-ansi/index.d.ts +1 -1
- package/node_modules/slice-ansi/index.js +89 -146
- package/node_modules/slice-ansi/package.json +5 -5
- package/node_modules/slice-ansi/readme.md +0 -1
- package/node_modules/slice-ansi/tokenize-ansi.js +1 -1
- package/package.json +14 -10
- package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts +188 -0
- package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts.map +1 -0
- package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js +293 -0
- package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js.map +1 -0
- package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/package.json +25 -0
- package/lib/cli/commands/db/snapshot/capture.mjs +0 -26
- package/lib/cli/renderers/db-snapshot-capture/text.mjs +0 -3
- package/node_modules/@alcalzone/ansi-tokenize/build/consts.d.ts +0 -17
- package/node_modules/@alcalzone/ansi-tokenize/build/consts.js +0 -28
- package/node_modules/@alcalzone/ansi-tokenize/build/consts.js.map +0 -1
- package/node_modules/ink/build/components/AnimationContext.d.ts +0 -9
- package/node_modules/ink/build/components/AnimationContext.js +0 -13
- package/node_modules/ink/build/components/AnimationContext.js.map +0 -1
- package/node_modules/ink/build/hooks/use-animation.d.ts +0 -49
- package/node_modules/ink/build/hooks/use-animation.js +0 -87
- package/node_modules/ink/build/hooks/use-animation.js.map +0 -1
- package/node_modules/ink/build/hooks/use-box-metrics.d.ts +0 -59
- package/node_modules/ink/build/hooks/use-box-metrics.js +0 -88
- package/node_modules/ink/build/hooks/use-box-metrics.js.map +0 -1
- package/node_modules/ink/build/hooks/use-paste.d.ts +0 -35
- package/node_modules/ink/build/hooks/use-paste.js +0 -62
- package/node_modules/ink/build/hooks/use-paste.js.map +0 -1
- package/node_modules/ink/build/hooks/use-window-size.d.ts +0 -18
- package/node_modules/ink/build/hooks/use-window-size.js +0 -22
- package/node_modules/ink/build/hooks/use-window-size.js.map +0 -1
- package/node_modules/wrap-ansi/index.js +0 -468
- /package/node_modules/{wrap-ansi → ink/node_modules/wrap-ansi}/license +0 -0
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
import stringWidth from 'string-width';
|
|
2
|
-
import stripAnsi from 'strip-ansi';
|
|
3
|
-
import ansiStyles from 'ansi-styles';
|
|
4
|
-
|
|
5
|
-
const ANSI_ESCAPE = '\u001B';
|
|
6
|
-
const ANSI_ESCAPE_CSI = '\u009B';
|
|
7
|
-
const ESCAPES = new Set([
|
|
8
|
-
ANSI_ESCAPE,
|
|
9
|
-
ANSI_ESCAPE_CSI,
|
|
10
|
-
]);
|
|
11
|
-
|
|
12
|
-
const ANSI_ESCAPE_BELL = '\u0007';
|
|
13
|
-
const ANSI_CSI = '[';
|
|
14
|
-
const ANSI_OSC = ']';
|
|
15
|
-
const ANSI_SGR_TERMINATOR = 'm';
|
|
16
|
-
const ANSI_SGR_RESET = 0;
|
|
17
|
-
const ANSI_SGR_RESET_FOREGROUND = 39;
|
|
18
|
-
const ANSI_SGR_RESET_BACKGROUND = 49;
|
|
19
|
-
const ANSI_SGR_RESET_UNDERLINE_COLOR = 59;
|
|
20
|
-
const ANSI_SGR_FOREGROUND_EXTENDED = 38;
|
|
21
|
-
const ANSI_SGR_BACKGROUND_EXTENDED = 48;
|
|
22
|
-
const ANSI_SGR_UNDERLINE_COLOR_EXTENDED = 58;
|
|
23
|
-
const ANSI_SGR_COLOR_MODE_256 = 5;
|
|
24
|
-
const ANSI_SGR_COLOR_MODE_RGB = 2;
|
|
25
|
-
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
26
|
-
const ANSI_ESCAPE_REGEX = new RegExp(`^\\u001B(?:\\${ANSI_CSI}(?<sgr>[0-9;]*)${ANSI_SGR_TERMINATOR}|${ANSI_ESCAPE_LINK}(?<uri>[^\\u0007\\u001B]*)(?:\\u0007|\\u001B\\\\))`);
|
|
27
|
-
const ANSI_ESCAPE_CSI_REGEX = new RegExp(`^\\u009B(?<sgr>[0-9;]*)${ANSI_SGR_TERMINATOR}`);
|
|
28
|
-
const ANSI_SGR_MODIFIER_CLOSE_CODES = new Set(ansiStyles.codes.values());
|
|
29
|
-
ANSI_SGR_MODIFIER_CLOSE_CODES.delete(ANSI_SGR_RESET);
|
|
30
|
-
|
|
31
|
-
const segmenter = new Intl.Segmenter();
|
|
32
|
-
const getGraphemes = string => Array.from(segmenter.segment(string), ({segment}) => segment);
|
|
33
|
-
const TAB_SIZE = 8;
|
|
34
|
-
|
|
35
|
-
const wrapAnsiCode = code => `${ANSI_ESCAPE}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
36
|
-
const wrapAnsiHyperlink = url => `${ANSI_ESCAPE}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
37
|
-
|
|
38
|
-
const getSgrTokens = sgrParameters => {
|
|
39
|
-
const codes = sgrParameters.split(';').map(sgrParameter => sgrParameter === '' ? ANSI_SGR_RESET : Number.parseInt(sgrParameter, 10));
|
|
40
|
-
const sgrTokens = [];
|
|
41
|
-
|
|
42
|
-
for (let index = 0; index < codes.length; index++) {
|
|
43
|
-
const code = codes[index];
|
|
44
|
-
|
|
45
|
-
if (!Number.isFinite(code)) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
(
|
|
51
|
-
code === ANSI_SGR_FOREGROUND_EXTENDED
|
|
52
|
-
|| code === ANSI_SGR_BACKGROUND_EXTENDED
|
|
53
|
-
|| code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED
|
|
54
|
-
)
|
|
55
|
-
) {
|
|
56
|
-
if (index + 1 >= codes.length) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const mode = codes[index + 1];
|
|
61
|
-
|
|
62
|
-
if (mode === ANSI_SGR_COLOR_MODE_256 && Number.isFinite(codes[index + 2])) {
|
|
63
|
-
sgrTokens.push([code, mode, codes[index + 2]]);
|
|
64
|
-
index += 2;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const red = codes[index + 2];
|
|
69
|
-
const green = codes[index + 3];
|
|
70
|
-
const blue = codes[index + 4];
|
|
71
|
-
if (
|
|
72
|
-
mode === ANSI_SGR_COLOR_MODE_RGB
|
|
73
|
-
&& Number.isFinite(red)
|
|
74
|
-
&& Number.isFinite(green)
|
|
75
|
-
&& Number.isFinite(blue)
|
|
76
|
-
) {
|
|
77
|
-
sgrTokens.push([code, mode, red, green, blue]);
|
|
78
|
-
index += 4;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
sgrTokens.push([code]);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return sgrTokens;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const removeActiveStyle = (activeStyles, family) => {
|
|
92
|
-
const activeStyleIndex = activeStyles.findIndex(activeStyle => activeStyle.family === family);
|
|
93
|
-
|
|
94
|
-
if (activeStyleIndex !== -1) {
|
|
95
|
-
activeStyles.splice(activeStyleIndex, 1);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const upsertActiveStyle = (activeStyles, nextActiveStyle) => {
|
|
100
|
-
removeActiveStyle(activeStyles, nextActiveStyle.family);
|
|
101
|
-
activeStyles.push(nextActiveStyle);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const removeModifierStylesByClose = (activeStyles, closeCode) => {
|
|
105
|
-
for (let index = activeStyles.length - 1; index >= 0; index--) {
|
|
106
|
-
const activeStyle = activeStyles[index];
|
|
107
|
-
if (activeStyle.family.startsWith('modifier-') && activeStyle.close === closeCode) {
|
|
108
|
-
activeStyles.splice(index, 1);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const getColorStyle = (code, sgrToken) => {
|
|
114
|
-
if ((code >= 30 && code <= 37) || (code >= 90 && code <= 97) || (code === ANSI_SGR_FOREGROUND_EXTENDED && sgrToken.length > 1)) {
|
|
115
|
-
return {
|
|
116
|
-
family: 'foreground',
|
|
117
|
-
open: sgrToken.join(';'),
|
|
118
|
-
close: ANSI_SGR_RESET_FOREGROUND,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if ((code >= 40 && code <= 47) || (code >= 100 && code <= 107) || (code === ANSI_SGR_BACKGROUND_EXTENDED && sgrToken.length > 1)) {
|
|
123
|
-
return {
|
|
124
|
-
family: 'background',
|
|
125
|
-
open: sgrToken.join(';'),
|
|
126
|
-
close: ANSI_SGR_RESET_BACKGROUND,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (code === ANSI_SGR_UNDERLINE_COLOR_EXTENDED && sgrToken.length > 1) {
|
|
131
|
-
return {
|
|
132
|
-
family: 'underlineColor',
|
|
133
|
-
open: sgrToken.join(';'),
|
|
134
|
-
close: ANSI_SGR_RESET_UNDERLINE_COLOR,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const applySgrResetCode = (code, activeStyles) => {
|
|
140
|
-
if (code === ANSI_SGR_RESET) {
|
|
141
|
-
activeStyles.length = 0;
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (code === ANSI_SGR_RESET_FOREGROUND) {
|
|
146
|
-
removeActiveStyle(activeStyles, 'foreground');
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (code === ANSI_SGR_RESET_BACKGROUND) {
|
|
151
|
-
removeActiveStyle(activeStyles, 'background');
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (code === ANSI_SGR_RESET_UNDERLINE_COLOR) {
|
|
156
|
-
removeActiveStyle(activeStyles, 'underlineColor');
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (ANSI_SGR_MODIFIER_CLOSE_CODES.has(code)) {
|
|
161
|
-
removeModifierStylesByClose(activeStyles, code);
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return false;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const applySgrToken = (sgrToken, activeStyles) => {
|
|
169
|
-
const [code] = sgrToken;
|
|
170
|
-
|
|
171
|
-
if (applySgrResetCode(code, activeStyles)) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const colorStyle = getColorStyle(code, sgrToken);
|
|
176
|
-
if (colorStyle) {
|
|
177
|
-
upsertActiveStyle(activeStyles, colorStyle);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const close = ansiStyles.codes.get(code);
|
|
182
|
-
if (close !== undefined && close !== ANSI_SGR_RESET) {
|
|
183
|
-
upsertActiveStyle(activeStyles, {
|
|
184
|
-
family: `modifier-${code}`,
|
|
185
|
-
open: sgrToken.join(';'),
|
|
186
|
-
close,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const applySgrParameters = (sgrParameters, activeStyles) => {
|
|
192
|
-
for (const sgrToken of getSgrTokens(sgrParameters)) {
|
|
193
|
-
applySgrToken(sgrToken, activeStyles);
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const applySgrResets = (sgrParameters, activeStyles) => {
|
|
198
|
-
for (const sgrToken of getSgrTokens(sgrParameters)) {
|
|
199
|
-
const [code] = sgrToken;
|
|
200
|
-
applySgrResetCode(code, activeStyles);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const applyLeadingSgrResets = (string, activeStyles) => {
|
|
205
|
-
let remainder = string;
|
|
206
|
-
|
|
207
|
-
while (remainder.length > 0) {
|
|
208
|
-
if (remainder.startsWith(ANSI_ESCAPE) && remainder[1] !== '\\') {
|
|
209
|
-
const match = ANSI_ESCAPE_REGEX.exec(remainder);
|
|
210
|
-
if (!match) {
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (match.groups.sgr !== undefined) {
|
|
215
|
-
applySgrResets(match.groups.sgr, activeStyles);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
remainder = remainder.slice(match[0].length);
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (remainder.startsWith(ANSI_ESCAPE_CSI)) {
|
|
223
|
-
const match = ANSI_ESCAPE_CSI_REGEX.exec(remainder);
|
|
224
|
-
if (!match || match.groups.sgr === undefined) {
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
applySgrResets(match.groups.sgr, activeStyles);
|
|
229
|
-
remainder = remainder.slice(match[0].length);
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const getClosingSgrSequence = activeStyles => [...activeStyles].reverse().map(activeStyle => wrapAnsiCode(activeStyle.close)).join('');
|
|
238
|
-
const getOpeningSgrSequence = activeStyles => activeStyles.map(activeStyle => wrapAnsiCode(activeStyle.open)).join('');
|
|
239
|
-
|
|
240
|
-
// Calculate the length of words split on ' ', ignoring
|
|
241
|
-
// the extra characters added by ANSI escape codes
|
|
242
|
-
const wordLengths = string => string.split(' ').map(word => stringWidth(word));
|
|
243
|
-
|
|
244
|
-
// Wrap a long word across multiple rows
|
|
245
|
-
// ANSI escape codes do not count towards length
|
|
246
|
-
const wrapWord = (rows, word, columns) => {
|
|
247
|
-
const characters = getGraphemes(word);
|
|
248
|
-
|
|
249
|
-
let isInsideEscape = false;
|
|
250
|
-
let isInsideLinkEscape = false;
|
|
251
|
-
let visible = stringWidth(stripAnsi(rows.at(-1)));
|
|
252
|
-
|
|
253
|
-
for (const [index, character] of characters.entries()) {
|
|
254
|
-
const characterLength = stringWidth(character);
|
|
255
|
-
|
|
256
|
-
if (visible + characterLength <= columns) {
|
|
257
|
-
rows[rows.length - 1] += character;
|
|
258
|
-
} else {
|
|
259
|
-
rows.push(character);
|
|
260
|
-
visible = 0;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (ESCAPES.has(character) && !(isInsideLinkEscape && character === ANSI_ESCAPE && characters[index + 1] === '\\')) {
|
|
264
|
-
isInsideEscape = true;
|
|
265
|
-
|
|
266
|
-
const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join('');
|
|
267
|
-
isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (isInsideEscape) {
|
|
271
|
-
if (isInsideLinkEscape) {
|
|
272
|
-
if (
|
|
273
|
-
character === ANSI_ESCAPE_BELL
|
|
274
|
-
|| (character === '\\' && index > 0 && characters[index - 1] === ANSI_ESCAPE) // ST terminator (ESC \)
|
|
275
|
-
) {
|
|
276
|
-
isInsideEscape = false;
|
|
277
|
-
isInsideLinkEscape = false;
|
|
278
|
-
}
|
|
279
|
-
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
280
|
-
isInsideEscape = false;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
visible += characterLength;
|
|
287
|
-
|
|
288
|
-
if (visible === columns && index < characters.length - 1) {
|
|
289
|
-
rows.push('');
|
|
290
|
-
visible = 0;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// It's possible that the last row we copy over is only
|
|
295
|
-
// ANSI escape characters, handle this edge-case
|
|
296
|
-
if (!visible && rows.at(-1).length > 0 && rows.length > 1) {
|
|
297
|
-
rows[rows.length - 2] += rows.pop();
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
// Trims spaces from a string ignoring invisible sequences
|
|
302
|
-
const stringVisibleTrimSpacesRight = string => {
|
|
303
|
-
const words = string.split(' ');
|
|
304
|
-
let last = words.length;
|
|
305
|
-
|
|
306
|
-
while (last > 0) {
|
|
307
|
-
if (stringWidth(words[last - 1]) > 0) {
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
last--;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (last === words.length) {
|
|
315
|
-
return string;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return words.slice(0, last).join(' ') + words.slice(last).join('');
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
const expandTabs = line => {
|
|
322
|
-
if (!line.includes('\t')) {
|
|
323
|
-
return line;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const segments = line.split('\t');
|
|
327
|
-
let visible = 0;
|
|
328
|
-
let expandedLine = '';
|
|
329
|
-
|
|
330
|
-
for (const [index, segment] of segments.entries()) {
|
|
331
|
-
expandedLine += segment;
|
|
332
|
-
visible += stringWidth(segment);
|
|
333
|
-
|
|
334
|
-
if (index < segments.length - 1) {
|
|
335
|
-
const spaces = TAB_SIZE - (visible % TAB_SIZE);
|
|
336
|
-
expandedLine += ' '.repeat(spaces);
|
|
337
|
-
visible += spaces;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return expandedLine;
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode.
|
|
345
|
-
//
|
|
346
|
-
// 'hard' will never allow a string to take up more than columns characters.
|
|
347
|
-
//
|
|
348
|
-
// 'soft' allows long words to expand past the column length.
|
|
349
|
-
const exec = (string, columns, options = {}) => {
|
|
350
|
-
if (options.trim !== false && string.trim() === '') {
|
|
351
|
-
return '';
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
let returnValue = '';
|
|
355
|
-
let escapeUrl;
|
|
356
|
-
const activeStyles = [];
|
|
357
|
-
|
|
358
|
-
const lengths = wordLengths(string);
|
|
359
|
-
let rows = [''];
|
|
360
|
-
|
|
361
|
-
for (const [index, word] of string.split(' ').entries()) {
|
|
362
|
-
if (options.trim !== false) {
|
|
363
|
-
rows[rows.length - 1] = rows.at(-1).trimStart();
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
let rowLength = stringWidth(rows.at(-1));
|
|
367
|
-
|
|
368
|
-
if (index !== 0) {
|
|
369
|
-
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
370
|
-
// If we start with a new word but the current row length equals the length of the columns, add a new row
|
|
371
|
-
rows.push('');
|
|
372
|
-
rowLength = 0;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (rowLength > 0 || options.trim === false) {
|
|
376
|
-
rows[rows.length - 1] += ' ';
|
|
377
|
-
rowLength++;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
|
|
382
|
-
if (options.hard && options.wordWrap !== false && lengths[index] > columns) {
|
|
383
|
-
const remainingColumns = columns - rowLength;
|
|
384
|
-
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
385
|
-
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
386
|
-
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
387
|
-
rows.push('');
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
wrapWord(rows, word, columns);
|
|
391
|
-
continue;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
|
|
395
|
-
if (options.wordWrap === false && rowLength < columns) {
|
|
396
|
-
wrapWord(rows, word, columns);
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
rows.push('');
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (rowLength + lengths[index] > columns && options.wordWrap === false) {
|
|
404
|
-
wrapWord(rows, word, columns);
|
|
405
|
-
continue;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
rows[rows.length - 1] += word;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (options.trim !== false) {
|
|
412
|
-
rows = rows.map(row => stringVisibleTrimSpacesRight(row));
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const preString = rows.join('\n');
|
|
416
|
-
const pre = getGraphemes(preString);
|
|
417
|
-
|
|
418
|
-
// We need to keep a separate index as `String#slice()` works on Unicode code units, while `pre` is an array of grapheme clusters.
|
|
419
|
-
let preStringIndex = 0;
|
|
420
|
-
|
|
421
|
-
for (const [index, character] of pre.entries()) {
|
|
422
|
-
returnValue += character;
|
|
423
|
-
|
|
424
|
-
if (character === ANSI_ESCAPE && pre[index + 1] !== '\\') {
|
|
425
|
-
const {groups} = ANSI_ESCAPE_REGEX.exec(preString.slice(preStringIndex)) || {groups: {}};
|
|
426
|
-
if (groups.sgr !== undefined) {
|
|
427
|
-
applySgrParameters(groups.sgr, activeStyles);
|
|
428
|
-
} else if (groups.uri !== undefined) {
|
|
429
|
-
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
430
|
-
}
|
|
431
|
-
} else if (character === ANSI_ESCAPE_CSI) {
|
|
432
|
-
const {groups} = ANSI_ESCAPE_CSI_REGEX.exec(preString.slice(preStringIndex)) || {groups: {}};
|
|
433
|
-
if (groups.sgr !== undefined) {
|
|
434
|
-
applySgrParameters(groups.sgr, activeStyles);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if (pre[index + 1] === '\n') {
|
|
439
|
-
if (escapeUrl) {
|
|
440
|
-
returnValue += wrapAnsiHyperlink('');
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
returnValue += getClosingSgrSequence(activeStyles);
|
|
444
|
-
} else if (character === '\n') {
|
|
445
|
-
const openingStyles = [...activeStyles];
|
|
446
|
-
applyLeadingSgrResets(preString.slice(preStringIndex + 1), openingStyles);
|
|
447
|
-
returnValue += getOpeningSgrSequence(openingStyles);
|
|
448
|
-
|
|
449
|
-
if (escapeUrl) {
|
|
450
|
-
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
preStringIndex += character.length;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return returnValue;
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
// For each newline, invoke the method separately
|
|
461
|
-
export default function wrapAnsi(string, columns, options) {
|
|
462
|
-
return String(string)
|
|
463
|
-
.normalize()
|
|
464
|
-
.replaceAll('\r\n', '\n')
|
|
465
|
-
.split('\n')
|
|
466
|
-
.map(line => exec(expandTabs(line), columns, options))
|
|
467
|
-
.join('\n');
|
|
468
|
-
}
|
|
File without changes
|