@reliverse/relinka 1.1.6 → 1.1.8
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/dist-npm/components/anykey/index.js +57 -77
- package/dist-npm/components/block/block.js +48 -61
- package/dist-npm/components/checkbox/index.js +178 -211
- package/dist-npm/components/confirm/confirm-main.js +85 -122
- package/dist-npm/components/confirm/confirm-three.js +24 -27
- package/dist-npm/components/confirm/index.js +36 -45
- package/dist-npm/components/core/Separator.js +15 -17
- package/dist-npm/components/core/create-prompt.js +101 -124
- package/dist-npm/components/core/errors.js +19 -15
- package/dist-npm/components/core/hook-engine.js +91 -120
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +16 -6
- package/dist-npm/components/core/lines.js +45 -54
- package/dist-npm/components/core/make-theme.js +21 -30
- package/dist-npm/components/core/position.js +27 -23
- package/dist-npm/components/core/promise-polyfill.js +11 -14
- package/dist-npm/components/core/screen-manager.js +59 -74
- package/dist-npm/components/core/theme.js +22 -32
- package/dist-npm/components/core/use-effect.js +9 -15
- package/dist-npm/components/core/use-keypress.js +19 -23
- package/dist-npm/components/core/use-memo.js +10 -16
- package/dist-npm/components/core/use-pagination.js +33 -32
- package/dist-npm/components/core/use-prefix.js +40 -38
- package/dist-npm/components/core/use-ref.js +2 -5
- package/dist-npm/components/core/use-state.js +15 -23
- package/dist-npm/components/core/useKeyPress.js +14 -17
- package/dist-npm/components/core/usePromptState.js +8 -14
- package/dist-npm/components/core/utils.js +7 -16
- package/dist-npm/components/date/date.js +173 -204
- package/dist-npm/components/editor/index.js +71 -92
- package/dist-npm/components/expand/index.js +96 -124
- package/dist-npm/components/figures/index.js +283 -294
- package/dist-npm/components/input/index.js +61 -87
- package/dist-npm/components/input/text-main.js +97 -124
- package/dist-npm/components/input/text.js +24 -28
- package/dist-npm/components/instance/basic.js +17 -25
- package/dist-npm/components/instance/browser.js +14 -18
- package/dist-npm/components/instance/reporter/basic.js +46 -65
- package/dist-npm/components/instance/reporter/browser.js +44 -47
- package/dist-npm/components/instance/reporter/fancy.js +83 -96
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +52 -62
- package/dist-npm/components/mono/monoTwo.js +35 -49
- package/dist-npm/components/multiselect/group-multiselect.js +55 -71
- package/dist-npm/components/multiselect/multi-select-two.js +97 -130
- package/dist-npm/components/multiselect/multi-select.js +43 -49
- package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
- package/dist-npm/components/multiselect/multiselect-main.js +158 -145
- package/dist-npm/components/multiselect/num-multi-select.js +97 -130
- package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
- package/dist-npm/components/next-steps/next-steps.js +23 -25
- package/dist-npm/components/number/index.js +78 -112
- package/dist-npm/components/number/number-main.js +95 -2
- package/dist-npm/components/password/index.js +54 -73
- package/dist-npm/components/password/password-main.js +119 -2
- package/dist-npm/components/password/password-three.js +26 -30
- package/dist-npm/components/progressbar/ProgressBar.js +45 -64
- package/dist-npm/components/progressbar/helper.js +33 -40
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +29 -44
- package/dist-npm/components/prompts/index.d.ts +1 -0
- package/dist-npm/components/prompts/index.js +46 -45
- package/dist-npm/components/prompts/prompt.js +211 -260
- package/dist-npm/components/prompts/promptTwo.js +561 -605
- package/dist-npm/components/prompts/relinka.js +237 -295
- package/dist-npm/components/range/range.js +247 -294
- package/dist-npm/components/rawlist/index.js +87 -107
- package/dist-npm/components/results/results.js +31 -37
- package/dist-npm/components/search/index.js +148 -193
- package/dist-npm/components/select/index.js +148 -186
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +124 -5
- package/dist-npm/components/select/select-key.js +24 -25
- package/dist-npm/components/select/select-main.d.ts +1 -0
- package/dist-npm/components/select/select-main.js +143 -133
- package/dist-npm/components/select/select-three.js +32 -36
- package/dist-npm/components/select/select-two.js +94 -87
- package/dist-npm/components/spinner/index.js +107 -136
- package/dist-npm/components/st-end/end.js +34 -26
- package/dist-npm/components/st-end/start.js +29 -15
- package/dist-npm/components/toggle/index.js +113 -137
- package/dist-npm/components/visual/animate/animate.js +53 -10
- package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
- package/dist-npm/main.js +1 -0
- package/dist-npm/testing/index.js +58 -83
- package/dist-npm/types/general.d.ts +1 -1
- package/dist-npm/types/general.js +0 -1
- package/dist-npm/types/index.js +2 -3
- package/dist-npm/types/keypress.js +35 -36
- package/dist-npm/types/readline.js +0 -1
- package/dist-npm/types/relinka.js +0 -1
- package/dist-npm/types/utils.js +0 -1
- package/dist-npm/utils/box.js +135 -137
- package/dist-npm/utils/color.js +65 -74
- package/dist-npm/utils/colorize.js +124 -156
- package/dist-npm/utils/component.js +532 -657
- package/dist-npm/utils/constants.js +64 -63
- package/dist-npm/utils/core.js +2 -3
- package/dist-npm/utils/decoder.js +244 -223
- package/dist-npm/utils/error.js +4 -9
- package/dist-npm/utils/errors.js +14 -4
- package/dist-npm/utils/format.js +19 -24
- package/dist-npm/utils/keypress.js +316 -414
- package/dist-npm/utils/log.js +11 -15
- package/dist-npm/utils/mapping.js +45 -52
- package/dist-npm/utils/messages.js +196 -183
- package/dist-npm/utils/platforms.js +16 -20
- package/dist-npm/utils/prompt-tmp.js +235 -286
- package/dist-npm/utils/prompt-two.js +235 -286
- package/dist-npm/utils/readline.js +5 -7
- package/dist-npm/utils/skeleton.js +130 -170
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +44 -58
- package/dist-npm/utils/terminal.js +23 -34
- package/dist-npm/utils/tree.js +30 -41
- package/dist-npm/utils/types.js +0 -1
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +36 -44
- package/package.json +14 -14
- package/dist-npm/mod.js +0 -2
- /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
|
@@ -1,185 +1,145 @@
|
|
|
1
|
-
import differ from
|
|
2
|
-
import esc from
|
|
3
|
-
import
|
|
4
|
-
import listenForKeys from
|
|
5
|
-
|
|
6
|
-
const isFn = (a) => typeof a === 'function';
|
|
7
|
-
|
|
1
|
+
import differ from "ansi-diff-stream";
|
|
2
|
+
import esc from "ansi-escapes";
|
|
3
|
+
import windowSize from "window-size";
|
|
4
|
+
import listenForKeys from "../utils/keypress.js";
|
|
8
5
|
export const action = (key) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (key.
|
|
12
|
-
|
|
13
|
-
return 'first';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (key.name === 'c') {
|
|
17
|
-
return 'abort';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (key.name === 'd') {
|
|
21
|
-
return 'abort';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (key.name === 'e') {
|
|
25
|
-
return 'last';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (key.name === 'g') {
|
|
29
|
-
return 'reset';
|
|
30
|
-
}
|
|
6
|
+
const code = key.raw.charCodeAt(0);
|
|
7
|
+
if (key.ctrl) {
|
|
8
|
+
if (key.name === "a") {
|
|
9
|
+
return "first";
|
|
31
10
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return 'submit';
|
|
11
|
+
if (key.name === "c") {
|
|
12
|
+
return "abort";
|
|
35
13
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return 'submit';
|
|
14
|
+
if (key.name === "d") {
|
|
15
|
+
return "abort";
|
|
39
16
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return 'delete';
|
|
17
|
+
if (key.name === "e") {
|
|
18
|
+
return "last";
|
|
43
19
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return 'abort';
|
|
20
|
+
if (key.name === "g") {
|
|
21
|
+
return "reset";
|
|
47
22
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
23
|
+
}
|
|
24
|
+
if (key.name === "return") {
|
|
25
|
+
return "submit";
|
|
26
|
+
}
|
|
27
|
+
if (key.name === "enter") {
|
|
28
|
+
return "submit";
|
|
29
|
+
}
|
|
30
|
+
if (key.name === "backspace") {
|
|
31
|
+
return "delete";
|
|
32
|
+
}
|
|
33
|
+
if (key.name === "abort") {
|
|
34
|
+
return "abort";
|
|
35
|
+
}
|
|
36
|
+
if (key.name === "escape") {
|
|
37
|
+
return "abort";
|
|
38
|
+
}
|
|
39
|
+
if (key.name === "tab") {
|
|
40
|
+
return "next";
|
|
41
|
+
}
|
|
42
|
+
if (key.name === "up") {
|
|
43
|
+
return "up";
|
|
44
|
+
}
|
|
45
|
+
if (key.name === "down") {
|
|
46
|
+
return "down";
|
|
47
|
+
}
|
|
48
|
+
if (key.name === "right") {
|
|
49
|
+
return "right";
|
|
50
|
+
}
|
|
51
|
+
if (key.name === "left") {
|
|
52
|
+
return "left";
|
|
53
|
+
}
|
|
54
|
+
if (code === 8747) {
|
|
55
|
+
return "left";
|
|
56
|
+
}
|
|
57
|
+
if (code === 402) {
|
|
58
|
+
return "right";
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
const onResize = (stream, cb) => {
|
|
63
|
+
stream.on("resize", cb);
|
|
64
|
+
const stopListening = () => {
|
|
65
|
+
stream.removeListener("resize", cb);
|
|
66
|
+
};
|
|
67
|
+
return stopListening;
|
|
68
|
+
};
|
|
69
|
+
const wrap = (p) => {
|
|
70
|
+
const wrappedPrompt = p;
|
|
71
|
+
wrappedPrompt.out = differ();
|
|
72
|
+
wrappedPrompt.out.pipe(process.stdout);
|
|
73
|
+
wrappedPrompt.bell = () => {
|
|
74
|
+
process.stdout.write(esc.beep);
|
|
75
|
+
};
|
|
76
|
+
if (typeof wrappedPrompt._ !== "function") {
|
|
77
|
+
wrappedPrompt._ = wrappedPrompt.bell;
|
|
78
|
+
}
|
|
79
|
+
const onKey = (key) => {
|
|
80
|
+
const a = action(key);
|
|
81
|
+
if (a === "abort") {
|
|
82
|
+
return wrappedPrompt.close();
|
|
59
83
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return 'down';
|
|
84
|
+
if (a === false) {
|
|
85
|
+
return wrappedPrompt._(key.raw);
|
|
63
86
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
87
|
+
if (typeof wrappedPrompt[a] === "function") {
|
|
88
|
+
wrappedPrompt[a](key);
|
|
89
|
+
} else {
|
|
90
|
+
wrappedPrompt.bell();
|
|
67
91
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
92
|
+
};
|
|
93
|
+
const onNewSize = () => {
|
|
94
|
+
const { width, height } = windowSize;
|
|
95
|
+
wrappedPrompt.out.reset();
|
|
96
|
+
wrappedPrompt.render(true);
|
|
97
|
+
};
|
|
98
|
+
let offKeypress = null;
|
|
99
|
+
let offResize = null;
|
|
100
|
+
const pause = () => {
|
|
101
|
+
if (!offKeypress) {
|
|
102
|
+
return;
|
|
71
103
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
104
|
+
offKeypress();
|
|
105
|
+
offKeypress = null;
|
|
106
|
+
if (offResize) {
|
|
107
|
+
offResize();
|
|
108
|
+
offResize = null;
|
|
75
109
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
110
|
+
process.stdout.write(esc.cursorShow);
|
|
111
|
+
};
|
|
112
|
+
const resume = () => {
|
|
113
|
+
if (offKeypress) {
|
|
114
|
+
return;
|
|
79
115
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
116
|
+
offKeypress = listenForKeys(process.stdin, onKey);
|
|
117
|
+
offResize = onResize(process.stdout, onNewSize);
|
|
118
|
+
process.stdout.write(esc.cursorHide);
|
|
119
|
+
};
|
|
120
|
+
wrappedPrompt.pause = pause;
|
|
121
|
+
wrappedPrompt.resume = resume;
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
let isClosed = false;
|
|
124
|
+
wrappedPrompt.close = () => {
|
|
125
|
+
if (isClosed) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
isClosed = true;
|
|
129
|
+
wrappedPrompt.out.unpipe(process.stdout);
|
|
130
|
+
pause();
|
|
131
|
+
if (wrappedPrompt.aborted) {
|
|
132
|
+
reject(new Error("Prompt aborted"));
|
|
133
|
+
} else {
|
|
134
|
+
resolve(wrappedPrompt.value);
|
|
135
|
+
}
|
|
88
136
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const wrap = (wrappedPrompt) => {
|
|
94
|
-
wrappedPrompt.out = differ();
|
|
95
|
-
wrappedPrompt.out.pipe(process.stdout);
|
|
96
|
-
wrappedPrompt.bell = () => {
|
|
97
|
-
process.stdout.write(esc.beep);
|
|
98
|
-
};
|
|
99
|
-
if (!isFn(wrappedPrompt._)) {
|
|
100
|
-
wrappedPrompt._ = wrappedPrompt.bell;
|
|
137
|
+
process.on("beforeExit", () => wrappedPrompt.close());
|
|
138
|
+
if (typeof wrappedPrompt.submit !== "function") {
|
|
139
|
+
wrappedPrompt.submit = wrappedPrompt.close;
|
|
101
140
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (a === 'abort') {
|
|
107
|
-
return wrappedPrompt.close();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!a) {
|
|
111
|
-
return wrappedPrompt._(key.raw);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (isFn(wrappedPrompt[a])) {
|
|
115
|
-
wrappedPrompt[a](key);
|
|
116
|
-
} else {
|
|
117
|
-
wrappedPrompt.bell();
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const onNewSize = () => {
|
|
122
|
-
wrappedPrompt.out.reset();
|
|
123
|
-
wrappedPrompt.render(true);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
let offKeypress = null;
|
|
127
|
-
let offResize = null;
|
|
128
|
-
|
|
129
|
-
const pause = () => {
|
|
130
|
-
if (!offKeypress) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
offKeypress();
|
|
135
|
-
offKeypress = null;
|
|
136
|
-
if (offResize) {
|
|
137
|
-
offResize();
|
|
138
|
-
offResize = null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
process.stdout.write(esc.cursorShow);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const resume = () => {
|
|
145
|
-
if (offKeypress) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
offKeypress = listenForKeys(process.stdin, onKey);
|
|
150
|
-
offResize = onResize(process.stdout, onNewSize);
|
|
151
|
-
process.stdout.write(esc.cursorHide);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
wrappedPrompt.pause = pause;
|
|
155
|
-
wrappedPrompt.resume = resume;
|
|
156
|
-
return new Promise((resolve, reject) => {
|
|
157
|
-
let isClosed = false;
|
|
158
|
-
|
|
159
|
-
wrappedPrompt.close = () => {
|
|
160
|
-
if (isClosed) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
isClosed = true;
|
|
165
|
-
wrappedPrompt.out.unpipe(process.stdout);
|
|
166
|
-
pause();
|
|
167
|
-
if (wrappedPrompt.aborted) {
|
|
168
|
-
reject(Error('Prompt aborted'));
|
|
169
|
-
} else {
|
|
170
|
-
resolve(wrappedPrompt.value);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
process.on('beforeExit', () => wrappedPrompt.close());
|
|
174
|
-
if (!isFn(wrappedPrompt.submit)) {
|
|
175
|
-
wrappedPrompt.submit = wrappedPrompt.close;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
resume();
|
|
179
|
-
wrappedPrompt.render(true);
|
|
180
|
-
});
|
|
141
|
+
resume();
|
|
142
|
+
wrappedPrompt.render(true);
|
|
143
|
+
});
|
|
181
144
|
};
|
|
182
|
-
|
|
183
|
-
export default Object.assign(wrap, {
|
|
184
|
-
action,
|
|
185
|
-
});
|
|
145
|
+
export default Object.assign(wrap, { action });
|
package/dist-npm/utils/stream.js
CHANGED
package/dist-npm/utils/string.js
CHANGED
|
@@ -1,67 +1,53 @@
|
|
|
1
1
|
const ansiRegex = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
].join(
|
|
5
|
-
|
|
2
|
+
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
|
|
3
|
+
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`
|
|
4
|
+
].join("|");
|
|
6
5
|
export function stripAnsi(text) {
|
|
7
|
-
|
|
6
|
+
return text.replace(new RegExp(ansiRegex, "g"), "");
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
8
|
+
export function centerAlign(str, len, space = " ") {
|
|
9
|
+
const free = len - str.length;
|
|
10
|
+
if (free <= 0) {
|
|
11
|
+
return str;
|
|
12
|
+
}
|
|
13
|
+
const freeLeft = Math.floor(free / 2);
|
|
14
|
+
let _str = "";
|
|
15
|
+
for (let i = 0; i < len; i++) {
|
|
16
|
+
_str += i < freeLeft || i >= freeLeft + str.length ? space : str[i - freeLeft];
|
|
17
|
+
}
|
|
18
|
+
return _str;
|
|
19
|
+
}
|
|
20
|
+
export function rightAlign(str, len, space = " ") {
|
|
21
|
+
const free = len - str.length;
|
|
22
|
+
if (free <= 0) {
|
|
23
|
+
return str;
|
|
24
|
+
}
|
|
25
|
+
let _str = "";
|
|
26
|
+
for (let i = 0; i < len; i++) {
|
|
27
|
+
_str += i < free ? space : str[i - free];
|
|
28
|
+
}
|
|
29
|
+
return _str;
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
export function leftAlign(str, len, space = " ") {
|
|
32
|
+
let _str = "";
|
|
33
|
+
for (let i = 0; i < len; i++) {
|
|
34
|
+
_str += i < str.length ? str[i] : space;
|
|
35
|
+
}
|
|
36
|
+
return _str;
|
|
37
|
+
}
|
|
38
|
+
export function align(alignment, str, len, space = " ") {
|
|
39
|
+
switch (alignment) {
|
|
40
|
+
case "left": {
|
|
41
|
+
return leftAlign(str, len, space);
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (let i = 0; i < len; i++) {
|
|
37
|
-
_str += i < free ? space : str[i - free];
|
|
43
|
+
case "right": {
|
|
44
|
+
return rightAlign(str, len, space);
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function leftAlign(str, len, space = ' ') {
|
|
44
|
-
let _str = '';
|
|
45
|
-
|
|
46
|
-
for (let i = 0; i < len; i++) {
|
|
47
|
-
_str += i < str.length ? str[i] : space;
|
|
46
|
+
case "center": {
|
|
47
|
+
return centerAlign(str, len, space);
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function align(alignment, str, len, space = ' ') {
|
|
54
|
-
switch(alignment) {
|
|
55
|
-
case 'left':
|
|
56
|
-
return leftAlign(str, len, space);
|
|
57
|
-
|
|
58
|
-
case 'right':
|
|
59
|
-
return rightAlign(str, len, space);
|
|
60
|
-
|
|
61
|
-
case 'center':
|
|
62
|
-
return centerAlign(str, len, space);
|
|
63
|
-
|
|
64
|
-
default:
|
|
65
|
-
return str;
|
|
49
|
+
default: {
|
|
50
|
+
return str;
|
|
66
51
|
}
|
|
52
|
+
}
|
|
67
53
|
}
|
|
@@ -1,44 +1,33 @@
|
|
|
1
|
-
import ansiEscapes from
|
|
2
|
-
import {cursor} from
|
|
3
|
-
import wrapAnsi from
|
|
4
|
-
import
|
|
5
|
-
import {msg} from './messages.js';
|
|
6
|
-
|
|
1
|
+
import ansiEscapes from "ansi-escapes";
|
|
2
|
+
import { cursor } from "sisteransi";
|
|
3
|
+
import wrapAnsi from "wrap-ansi";
|
|
4
|
+
import { msg } from "./messages.js";
|
|
7
5
|
export function removeCursor() {
|
|
8
|
-
|
|
6
|
+
process.stdout.write(cursor.hide);
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
export function restoreCursor() {
|
|
12
|
-
|
|
9
|
+
process.stdout.write(cursor.show);
|
|
13
10
|
}
|
|
14
|
-
|
|
15
11
|
export function deleteLastLine() {
|
|
16
|
-
|
|
12
|
+
process.stdout.write(ansiEscapes.cursorUp(1) + ansiEscapes.eraseLine);
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
export function deleteLastLines(count) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
process.stdout.write(ansiEscapes.eraseLines(count));
|
|
15
|
+
if (count <= 0) {
|
|
16
|
+
msg({
|
|
17
|
+
type: "M_ERROR",
|
|
18
|
+
title: "Count is less than or equal to 0. Nothing to delete."
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
process.stdout.write(ansiEscapes.eraseLines(count));
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
export function countLines(text) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
lineCount += wrapped.split('\n').length;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return lineCount;
|
|
25
|
+
const terminalWidth = process.stdout.columns || 80;
|
|
26
|
+
const lines = text.split("\n");
|
|
27
|
+
let lineCount = 0;
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
const wrapped = wrapAnsi(line, terminalWidth, { hard: true });
|
|
30
|
+
lineCount += wrapped.split("\n").length;
|
|
31
|
+
}
|
|
32
|
+
return lineCount;
|
|
44
33
|
}
|
package/dist-npm/utils/tree.js
CHANGED
|
@@ -1,48 +1,37 @@
|
|
|
1
|
-
import {colorize} from
|
|
2
|
-
|
|
3
|
-
const isString = (a) => typeof a === 'string';
|
|
4
|
-
|
|
1
|
+
import { colorize } from "./color.js";
|
|
5
2
|
export function formatTree(items, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return tree;
|
|
3
|
+
options = {
|
|
4
|
+
prefix: " ",
|
|
5
|
+
...options
|
|
6
|
+
};
|
|
7
|
+
const tree = _buildTree(items, options).join("");
|
|
8
|
+
if (options?.color) {
|
|
9
|
+
return colorize(options.color, tree);
|
|
10
|
+
}
|
|
11
|
+
return tree;
|
|
17
12
|
}
|
|
18
|
-
|
|
19
13
|
function _buildTree(items, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (isString(item)) {
|
|
29
|
-
chunks.push(`${prefix}${item}
|
|
14
|
+
const chunks = [];
|
|
15
|
+
const total = items.length - 1;
|
|
16
|
+
for (let i = 0; i <= total; i++) {
|
|
17
|
+
const item = items[i];
|
|
18
|
+
const isLast = i === total;
|
|
19
|
+
const prefix = isLast ? `${options?.prefix}\u2514\u2500` : `${options?.prefix}\u251C\u2500`;
|
|
20
|
+
if (typeof item === "string") {
|
|
21
|
+
chunks.push(`${prefix}${item}
|
|
30
22
|
`);
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
} else {
|
|
24
|
+
const log = `${prefix}${item.text}
|
|
33
25
|
`;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
chunks.push(..._tree);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
26
|
+
chunks.push(item.color ? colorize(item.color, log) : log);
|
|
27
|
+
if (item.children) {
|
|
28
|
+
const _tree = _buildTree(item.children, {
|
|
29
|
+
...options,
|
|
30
|
+
prefix: `${options?.prefix}${isLast ? " " : "\u2502 "}`
|
|
31
|
+
});
|
|
32
|
+
chunks.push(..._tree);
|
|
33
|
+
}
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
}
|
|
36
|
+
return chunks;
|
|
48
37
|
}
|
package/dist-npm/utils/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist-npm/utils/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./box.js";
|
|
2
|
+
export * from "./color.js";
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
4
|
+
stripAnsi,
|
|
5
|
+
centerAlign,
|
|
6
|
+
rightAlign,
|
|
7
|
+
leftAlign,
|
|
8
|
+
align
|
|
9
|
+
} from "./string.js";
|