@reliverse/relinka 1.1.7 → 1.1.9
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 +187 -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,697 +1,653 @@
|
|
|
1
|
-
import isUnicodeSupported from
|
|
2
|
-
import {cursor, erase} from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export {isCancel} from '../../components/prompts/prompt.js';
|
|
16
|
-
const isString = (a) => typeof a === 'string';
|
|
1
|
+
import isUnicodeSupported from "is-unicode-supported";
|
|
2
|
+
import { cursor, erase } from "sisteransi";
|
|
3
|
+
import block from "../../components/block/block.js";
|
|
4
|
+
import ConfirmPrompt from "../../components/confirm/confirm-three.js";
|
|
5
|
+
import TextPrompt from "../../components/input/text.js";
|
|
6
|
+
import GroupMultiSelectPrompt from "../../components/multiselect/group-multiselect.js";
|
|
7
|
+
import MultiSelectPrompt from "../../components/multiselect/multi-select.js";
|
|
8
|
+
import PasswordPrompt from "../../components/password/password-three.js";
|
|
9
|
+
import { isCancel } from "../../components/prompts/prompt.js";
|
|
10
|
+
import SelectKeyPrompt from "../../components/select/select-key.js";
|
|
11
|
+
import SelectPrompt from "../../components/select/select-three.js";
|
|
12
|
+
import { colors as color } from "../../utils/color.js";
|
|
13
|
+
export { isCancel } from "../../components/prompts/prompt.js";
|
|
17
14
|
const unicode = isUnicodeSupported();
|
|
18
15
|
const s = (c, fallback) => unicode ? c : fallback;
|
|
19
|
-
const S_STEP_ACTIVE = s(
|
|
20
|
-
const S_STEP_CANCEL = s(
|
|
21
|
-
const S_STEP_ERROR = s(
|
|
22
|
-
const S_STEP_SUBMIT = s(
|
|
23
|
-
const S_BAR_START =
|
|
24
|
-
const S_BAR =
|
|
25
|
-
const S_BAR_END =
|
|
26
|
-
const S_RADIO_ACTIVE = s(
|
|
27
|
-
const S_RADIO_INACTIVE = s(
|
|
28
|
-
const S_CHECKBOX_ACTIVE = s(
|
|
29
|
-
const S_CHECKBOX_SELECTED = s(
|
|
30
|
-
const S_CHECKBOX_INACTIVE = s(
|
|
31
|
-
const S_PASSWORD_MASK = s(
|
|
32
|
-
const S_BAR_H = s(
|
|
33
|
-
const S_CORNER_TOP_RIGHT = s(
|
|
34
|
-
const S_CONNECT_LEFT = s(
|
|
35
|
-
const S_CORNER_BOTTOM_RIGHT = s(
|
|
36
|
-
const S_INFO = s(
|
|
37
|
-
const S_SUCCESS = s(
|
|
38
|
-
const S_WARN = s(
|
|
39
|
-
const S_ERROR = s(
|
|
40
|
-
|
|
16
|
+
const S_STEP_ACTIVE = s("\u276F", ">");
|
|
17
|
+
const S_STEP_CANCEL = s("\u25A0", "x");
|
|
18
|
+
const S_STEP_ERROR = s("\u25B2", "x");
|
|
19
|
+
const S_STEP_SUBMIT = s("\u2714", "\u221A");
|
|
20
|
+
const S_BAR_START = "";
|
|
21
|
+
const S_BAR = "";
|
|
22
|
+
const S_BAR_END = "";
|
|
23
|
+
const S_RADIO_ACTIVE = s("\u25CF", ">");
|
|
24
|
+
const S_RADIO_INACTIVE = s("\u25CB", " ");
|
|
25
|
+
const S_CHECKBOX_ACTIVE = s("\u25FB", "[\u2022]");
|
|
26
|
+
const S_CHECKBOX_SELECTED = s("\u25FC", "[+]");
|
|
27
|
+
const S_CHECKBOX_INACTIVE = s("\u25FB", "[ ]");
|
|
28
|
+
const S_PASSWORD_MASK = s("\u25AA", "\u2022");
|
|
29
|
+
const S_BAR_H = s("\u2500", "-");
|
|
30
|
+
const S_CORNER_TOP_RIGHT = s("\u256E", "+");
|
|
31
|
+
const S_CONNECT_LEFT = s("\u251C", "+");
|
|
32
|
+
const S_CORNER_BOTTOM_RIGHT = s("\u256F", "+");
|
|
33
|
+
const S_INFO = s("\u25CF", "\u2022");
|
|
34
|
+
const S_SUCCESS = s("\u25C6", "*");
|
|
35
|
+
const S_WARN = s("\u25B2", "!");
|
|
36
|
+
const S_ERROR = s("\u25A0", "x");
|
|
41
37
|
const symbol = (state) => {
|
|
42
|
-
|
|
43
|
-
case
|
|
44
|
-
case
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
case 'error':
|
|
51
|
-
return color.yellow(S_STEP_ERROR);
|
|
52
|
-
|
|
53
|
-
case 'submit':
|
|
54
|
-
return color.green(S_STEP_SUBMIT);
|
|
38
|
+
switch (state) {
|
|
39
|
+
case "initial":
|
|
40
|
+
case "active": {
|
|
41
|
+
return color.cyan(S_STEP_ACTIVE);
|
|
42
|
+
}
|
|
43
|
+
case "cancel": {
|
|
44
|
+
return color.red(S_STEP_CANCEL);
|
|
55
45
|
}
|
|
46
|
+
case "error": {
|
|
47
|
+
return color.yellow(S_STEP_ERROR);
|
|
48
|
+
}
|
|
49
|
+
case "submit": {
|
|
50
|
+
return color.green(S_STEP_SUBMIT);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
56
53
|
};
|
|
57
|
-
|
|
58
54
|
export const text = (opts) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
return new TextPrompt({
|
|
56
|
+
validate: opts.validate,
|
|
57
|
+
placeholder: opts.placeholder,
|
|
58
|
+
defaultValue: opts.defaultValue,
|
|
59
|
+
initialValue: opts.initialValue,
|
|
60
|
+
render() {
|
|
61
|
+
const title = `${color.gray(S_BAR)}
|
|
66
62
|
${symbol(this.state)} ${opts.message}
|
|
67
63
|
`;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
${color.yellow(S_BAR_END)} ${color.yellow(
|
|
64
|
+
const placeholder = opts.placeholder ? color.inverse(opts.placeholder?.[0] ?? "") + color.dim(opts.placeholder?.slice(1) ?? "") : color.inverse(color.hidden("_"));
|
|
65
|
+
const value = this.value ? this.valueWithCursor : placeholder;
|
|
66
|
+
switch (this.state) {
|
|
67
|
+
case "error": {
|
|
68
|
+
return `${title.trim()}
|
|
69
|
+
${color.yellow(
|
|
70
|
+
S_BAR
|
|
71
|
+
)} ${value}
|
|
72
|
+
${color.yellow(S_BAR_END)} ${color.yellow(
|
|
73
|
+
this.error
|
|
74
|
+
)}
|
|
77
75
|
`;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
${color.
|
|
76
|
+
}
|
|
77
|
+
case "submit": {
|
|
78
|
+
return `${title}${color.gray(S_BAR)} ${color.dim(
|
|
79
|
+
this.value || opts.placeholder
|
|
80
|
+
)}`;
|
|
81
|
+
}
|
|
82
|
+
case "cancel": {
|
|
83
|
+
return `${title}${color.gray(S_BAR)} ${color.strikethrough(
|
|
84
|
+
color.dim(this.value ?? "")
|
|
85
|
+
)}${this.value?.trim() ? "\n" + color.gray(S_BAR) : ""}`;
|
|
86
|
+
}
|
|
87
|
+
default: {
|
|
88
|
+
return `${title}${color.cyan(S_BAR)} ${value}
|
|
89
|
+
${color.cyan(
|
|
90
|
+
S_BAR_END
|
|
91
|
+
)}
|
|
88
92
|
`;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}).prompt();
|
|
92
97
|
};
|
|
93
98
|
export const password = (opts) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
return new PasswordPrompt({
|
|
100
|
+
validate: opts.validate,
|
|
101
|
+
mask: opts.mask ?? S_PASSWORD_MASK,
|
|
102
|
+
render() {
|
|
103
|
+
const title = `${color.gray(S_BAR)}
|
|
99
104
|
${symbol(this.state)} ${opts.message}
|
|
100
105
|
`;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
${color.yellow(S_BAR_END)} ${color.yellow(
|
|
106
|
+
const value = this.valueWithCursor;
|
|
107
|
+
const masked = this.masked;
|
|
108
|
+
switch (this.state) {
|
|
109
|
+
case "error": {
|
|
110
|
+
return `${title.trim()}
|
|
111
|
+
${color.yellow(
|
|
112
|
+
S_BAR
|
|
113
|
+
)} ${masked}
|
|
114
|
+
${color.yellow(S_BAR_END)} ${color.yellow(
|
|
115
|
+
this.error
|
|
116
|
+
)}
|
|
110
117
|
`;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
}
|
|
119
|
+
case "submit": {
|
|
120
|
+
return `${title}${color.gray(S_BAR)} ${color.dim(masked)}`;
|
|
121
|
+
}
|
|
122
|
+
case "cancel": {
|
|
123
|
+
return `${title}${color.gray(S_BAR)} ${color.strikethrough(
|
|
124
|
+
color.dim(masked ?? "")
|
|
125
|
+
)}${masked ? "\n" + color.gray(S_BAR) : ""}`;
|
|
126
|
+
}
|
|
127
|
+
default: {
|
|
128
|
+
return `${title}${color.cyan(S_BAR)} ${value}
|
|
129
|
+
${color.cyan(
|
|
130
|
+
S_BAR_END
|
|
131
|
+
)}
|
|
121
132
|
`;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}).prompt();
|
|
125
137
|
};
|
|
126
138
|
export const confirm = (opts) => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const title = `${color.gray(S_BAR)}
|
|
139
|
+
const active = opts.active ?? "Yes";
|
|
140
|
+
const inactive = opts.inactive ?? "No";
|
|
141
|
+
return new ConfirmPrompt({
|
|
142
|
+
active,
|
|
143
|
+
inactive,
|
|
144
|
+
initialValue: opts.initialValue ?? true,
|
|
145
|
+
render() {
|
|
146
|
+
const title = `${color.gray(S_BAR)}
|
|
136
147
|
${symbol(this.state)} ${opts.message}
|
|
137
148
|
`;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
const value = this.value ? active : inactive;
|
|
150
|
+
switch (this.state) {
|
|
151
|
+
case "submit": {
|
|
152
|
+
return `${title}${color.gray(S_BAR)} ${color.dim(value)}`;
|
|
153
|
+
}
|
|
154
|
+
case "cancel": {
|
|
155
|
+
return `${title}${color.gray(S_BAR)} ${color.strikethrough(
|
|
156
|
+
color.dim(value)
|
|
157
|
+
)}
|
|
147
158
|
${color.gray(S_BAR)}`;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
159
|
+
}
|
|
160
|
+
default: {
|
|
161
|
+
return `${title}${color.cyan(S_BAR)} ${this.value ? `${color.green(S_RADIO_ACTIVE)} ${active}` : `${color.dim(S_RADIO_INACTIVE)} ${color.dim(active)}`} ${color.dim("/")} ${this.value ? `${color.dim(S_RADIO_INACTIVE)} ${color.dim(inactive)}` : `${color.green(S_RADIO_ACTIVE)} ${inactive}`}
|
|
151
162
|
${color.cyan(S_BAR_END)}
|
|
152
163
|
`;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}).prompt();
|
|
156
168
|
};
|
|
157
169
|
export const select = (opts) => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
initialValue: opts.initialValue,
|
|
179
|
-
render() {
|
|
180
|
-
const title = `${color.gray(S_BAR)}
|
|
170
|
+
const opt = (option, state) => {
|
|
171
|
+
const label = option.label ?? String(option.value);
|
|
172
|
+
switch (state) {
|
|
173
|
+
case "active": {
|
|
174
|
+
return `${color.green(S_RADIO_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
|
|
175
|
+
}
|
|
176
|
+
case "selected": {
|
|
177
|
+
return color.dim(label);
|
|
178
|
+
}
|
|
179
|
+
case "cancelled": {
|
|
180
|
+
return color.strikethrough(color.dim(label));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return `${color.dim(S_RADIO_INACTIVE)} ${color.dim(label)}`;
|
|
184
|
+
};
|
|
185
|
+
return new SelectPrompt({
|
|
186
|
+
options: opts.options,
|
|
187
|
+
initialValue: opts.initialValue,
|
|
188
|
+
render() {
|
|
189
|
+
const title = `${color.gray(S_BAR)}
|
|
181
190
|
${symbol(this.state)} ${opts.message}
|
|
182
191
|
`;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
192
|
+
switch (this.state) {
|
|
193
|
+
case "submit": {
|
|
194
|
+
const selectedOption = this.options[this.cursor];
|
|
195
|
+
if (!selectedOption) {
|
|
196
|
+
throw new Error("Selected option is undefined");
|
|
197
|
+
}
|
|
198
|
+
return `${title}${color.gray(S_BAR)} ${opt(
|
|
199
|
+
selectedOption,
|
|
200
|
+
"selected"
|
|
201
|
+
)}`;
|
|
202
|
+
}
|
|
203
|
+
case "cancel": {
|
|
204
|
+
const cancelledOption = this.options[this.cursor];
|
|
205
|
+
if (!cancelledOption) {
|
|
206
|
+
throw new Error("Cancelled option is undefined");
|
|
207
|
+
}
|
|
208
|
+
return `${title}${color.gray(S_BAR)} ${opt(
|
|
209
|
+
cancelledOption,
|
|
210
|
+
"cancelled"
|
|
211
|
+
)}
|
|
203
212
|
${color.gray(S_BAR)}`;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
.map((option, i) => opt(option, i === this.cursor ? 'active' : 'inactive'))
|
|
210
|
-
.join(`
|
|
213
|
+
}
|
|
214
|
+
default: {
|
|
215
|
+
return `${title}${color.cyan(S_BAR)} ${this.options.map(
|
|
216
|
+
(option, i) => opt(option, i === this.cursor ? "active" : "inactive")
|
|
217
|
+
).join(`
|
|
211
218
|
${color.cyan(S_BAR)} `)}
|
|
212
219
|
${color.cyan(S_BAR_END)}
|
|
213
220
|
`;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}).prompt();
|
|
217
225
|
};
|
|
218
226
|
export const selectKey = (opts) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const title = `${color.gray(S_BAR)}
|
|
227
|
+
const opt = (option, state = "inactive") => {
|
|
228
|
+
const label = option.label ?? String(option.value);
|
|
229
|
+
switch (state) {
|
|
230
|
+
case "selected": {
|
|
231
|
+
return color.dim(label);
|
|
232
|
+
}
|
|
233
|
+
case "cancelled": {
|
|
234
|
+
return color.strikethrough(color.dim(label));
|
|
235
|
+
}
|
|
236
|
+
case "active": {
|
|
237
|
+
return `${color.bgCyan(color.gray(` ${option.value} `))} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return `${color.gray(
|
|
241
|
+
color.bgWhite(color.inverse(` ${option.value} `))
|
|
242
|
+
)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
|
|
243
|
+
};
|
|
244
|
+
return new SelectKeyPrompt({
|
|
245
|
+
options: opts.options,
|
|
246
|
+
initialValue: opts.initialValue,
|
|
247
|
+
render() {
|
|
248
|
+
const title = `${color.gray(S_BAR)}
|
|
242
249
|
${symbol(this.state)} ${opts.message}
|
|
243
250
|
`;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
251
|
+
switch (this.state) {
|
|
252
|
+
case "submit": {
|
|
253
|
+
const selectedOption = this.options.find(
|
|
254
|
+
(opt2) => opt2.value === this.value
|
|
255
|
+
);
|
|
256
|
+
if (!selectedOption) {
|
|
257
|
+
throw new Error("Selected option not found");
|
|
258
|
+
}
|
|
259
|
+
return `${title}${color.gray(S_BAR)} ${opt(
|
|
260
|
+
selectedOption,
|
|
261
|
+
"selected"
|
|
262
|
+
)}`;
|
|
263
|
+
}
|
|
264
|
+
case "cancel": {
|
|
265
|
+
const cancelledOption = this.options[0];
|
|
266
|
+
if (!cancelledOption) {
|
|
267
|
+
throw new Error("Cancelled option is undefined");
|
|
268
|
+
}
|
|
269
|
+
return `${title}${color.gray(S_BAR)} ${opt(
|
|
270
|
+
cancelledOption,
|
|
271
|
+
"cancelled"
|
|
272
|
+
)}
|
|
264
273
|
${color.gray(S_BAR)}`;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
.map((option, i) => opt(option, i === this.cursor ? 'active' : 'inactive'))
|
|
271
|
-
.join(`
|
|
274
|
+
}
|
|
275
|
+
default: {
|
|
276
|
+
return `${title}${color.cyan(S_BAR)} ${this.options.map(
|
|
277
|
+
(option, i) => opt(option, i === this.cursor ? "active" : "inactive")
|
|
278
|
+
).join(`
|
|
272
279
|
${color.cyan(S_BAR)} `)}
|
|
273
280
|
${color.cyan(S_BAR_END)}
|
|
274
281
|
`;
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
}).prompt();
|
|
278
|
-
};
|
|
279
|
-
export const multiselect = (opts) => {
|
|
280
|
-
const opt = (option, state) => {
|
|
281
|
-
const label = option.label ?? String(option.value);
|
|
282
|
-
|
|
283
|
-
switch(state) {
|
|
284
|
-
case 'active':
|
|
285
|
-
return `${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
|
|
286
|
-
|
|
287
|
-
case 'selected':
|
|
288
|
-
return `${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
|
|
289
|
-
|
|
290
|
-
case 'cancelled':
|
|
291
|
-
return color.strikethrough(color.dim(label));
|
|
292
|
-
|
|
293
|
-
case 'active-selected':
|
|
294
|
-
return `${color.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
|
|
295
|
-
|
|
296
|
-
case 'submitted':
|
|
297
|
-
return color.dim(label);
|
|
298
282
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}).prompt();
|
|
286
|
+
};
|
|
287
|
+
export const multiselect = async (opts) => {
|
|
288
|
+
const opt = (option, state) => {
|
|
289
|
+
const label = option.label ?? String(option.value);
|
|
290
|
+
switch (state) {
|
|
291
|
+
case "active": {
|
|
292
|
+
return `${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
|
|
293
|
+
}
|
|
294
|
+
case "selected": {
|
|
295
|
+
return `${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
|
|
296
|
+
}
|
|
297
|
+
case "cancelled": {
|
|
298
|
+
return color.strikethrough(color.dim(label));
|
|
299
|
+
}
|
|
300
|
+
case "active-selected": {
|
|
301
|
+
return `${color.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
|
|
302
|
+
}
|
|
303
|
+
case "submitted": {
|
|
304
|
+
return color.dim(label);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return `${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(label)}`;
|
|
308
|
+
};
|
|
309
|
+
return new MultiSelectPrompt({
|
|
310
|
+
options: opts.options,
|
|
311
|
+
initialValues: opts.initialValues,
|
|
312
|
+
required: opts.required ?? true,
|
|
313
|
+
cursorAt: opts.cursorAt,
|
|
314
|
+
validate(selected) {
|
|
315
|
+
if (this.required && selected.length === 0) {
|
|
316
|
+
return `Please select at least one option.
|
|
317
|
+
${color.reset(
|
|
318
|
+
color.dim(
|
|
319
|
+
`Press ${color.gray(
|
|
320
|
+
color.bgWhite(color.inverse(" space "))
|
|
321
|
+
)} to select, ${color.gray(
|
|
322
|
+
color.bgWhite(color.inverse(" enter "))
|
|
323
|
+
)} to submit`
|
|
324
|
+
)
|
|
325
|
+
)}`;
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
render() {
|
|
329
|
+
const title = `${color.gray(S_BAR)}
|
|
317
330
|
${symbol(this.state)} ${opts.message}
|
|
318
331
|
`;
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
switch (this.state) {
|
|
333
|
+
case "submit": {
|
|
334
|
+
return `${title}${color.gray(S_BAR)} ${this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(color.dim(", ")) || color.dim("none")}`;
|
|
335
|
+
}
|
|
336
|
+
case "cancel": {
|
|
337
|
+
const label = this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "cancelled")).join(color.dim(", "));
|
|
338
|
+
return `${title}${color.gray(S_BAR)} ${label.trim() ? `${label}
|
|
339
|
+
${color.gray(S_BAR)}` : ""}`;
|
|
340
|
+
}
|
|
341
|
+
case "error": {
|
|
342
|
+
const footer = this.error.split("\n").map(
|
|
343
|
+
(ln, i) => i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`
|
|
344
|
+
).join("\n");
|
|
345
|
+
return title + color.yellow(S_BAR) + " " + this.options.map((option, i) => {
|
|
346
|
+
const selected = this.value.includes(option.value);
|
|
347
|
+
const active = i === this.cursor;
|
|
348
|
+
if (active && selected) {
|
|
349
|
+
return opt(option, "active-selected");
|
|
350
|
+
}
|
|
351
|
+
if (selected) {
|
|
352
|
+
return opt(option, "selected");
|
|
337
353
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
.options
|
|
349
|
-
.map((option, i) => {
|
|
350
|
-
const selected = this.value.includes(option.value);
|
|
351
|
-
const active = i === this.cursor;
|
|
352
|
-
|
|
353
|
-
if (active && selected) {
|
|
354
|
-
return opt(option, 'active-selected');
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if (selected) {
|
|
358
|
-
return opt(option, 'selected');
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return opt(option, active ? 'active' : 'inactive');
|
|
362
|
-
})
|
|
363
|
-
.join(`
|
|
364
|
-
${color.yellow(S_BAR)} `) +
|
|
365
|
-
'\n' + footer +
|
|
366
|
-
'\n';
|
|
354
|
+
return opt(option, active ? "active" : "inactive");
|
|
355
|
+
}).join(`
|
|
356
|
+
${color.yellow(S_BAR)} `) + "\n" + footer + "\n";
|
|
357
|
+
}
|
|
358
|
+
default: {
|
|
359
|
+
return `${title}${color.cyan(S_BAR)} ${this.options.map((option, i) => {
|
|
360
|
+
const selected = this.value.includes(option.value);
|
|
361
|
+
const active = i === this.cursor;
|
|
362
|
+
if (active && selected) {
|
|
363
|
+
return opt(option, "active-selected");
|
|
367
364
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const selected = this.value.includes(option.value);
|
|
374
|
-
const active = i === this.cursor;
|
|
375
|
-
|
|
376
|
-
if (active && selected) {
|
|
377
|
-
return opt(option, 'active-selected');
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (selected) {
|
|
381
|
-
return opt(option, 'selected');
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return opt(option, active ? 'active' : 'inactive');
|
|
385
|
-
})
|
|
386
|
-
.join(`
|
|
365
|
+
if (selected) {
|
|
366
|
+
return opt(option, "selected");
|
|
367
|
+
}
|
|
368
|
+
return opt(option, active ? "active" : "inactive");
|
|
369
|
+
}).join(`
|
|
387
370
|
${color.cyan(S_BAR)} `)}
|
|
388
371
|
${color.cyan(S_BAR_END)}
|
|
389
372
|
`;
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}).prompt();
|
|
393
377
|
};
|
|
394
378
|
export const groupMultiselect = (opts) => {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
379
|
+
const opt = (option, state, options = []) => {
|
|
380
|
+
const label = option.label ?? String(option.value);
|
|
381
|
+
const isItem = typeof option.group === "string";
|
|
382
|
+
const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true });
|
|
383
|
+
const isLast = isItem && next.group === true;
|
|
384
|
+
const prefix = isItem ? `${isLast ? S_BAR_END : S_BAR} ` : "";
|
|
385
|
+
switch (state) {
|
|
386
|
+
case "active": {
|
|
387
|
+
return `${color.dim(prefix)}${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
|
|
388
|
+
}
|
|
389
|
+
case "group-active": {
|
|
390
|
+
return `${prefix}${color.cyan(S_CHECKBOX_ACTIVE)} ${color.dim(label)}`;
|
|
391
|
+
}
|
|
392
|
+
case "group-active-selected": {
|
|
393
|
+
return `${prefix}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(
|
|
394
|
+
label
|
|
395
|
+
)}`;
|
|
396
|
+
}
|
|
397
|
+
case "selected": {
|
|
398
|
+
return `${color.dim(prefix)}${color.green(
|
|
399
|
+
S_CHECKBOX_SELECTED
|
|
400
|
+
)} ${color.dim(label)}`;
|
|
401
|
+
}
|
|
402
|
+
case "cancelled": {
|
|
403
|
+
return color.strikethrough(color.dim(label));
|
|
404
|
+
}
|
|
405
|
+
case "active-selected": {
|
|
406
|
+
return `${color.dim(prefix)}${color.green(
|
|
407
|
+
S_CHECKBOX_SELECTED
|
|
408
|
+
)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
|
|
409
|
+
}
|
|
410
|
+
case "submitted": {
|
|
411
|
+
return color.dim(label);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return `${color.dim(prefix)}${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(
|
|
415
|
+
label
|
|
416
|
+
)}`;
|
|
417
|
+
};
|
|
418
|
+
return new GroupMultiSelectPrompt({
|
|
419
|
+
options: opts.options,
|
|
420
|
+
initialValues: opts.initialValues,
|
|
421
|
+
required: opts.required ?? true,
|
|
422
|
+
cursorAt: opts.cursorAt,
|
|
423
|
+
validate(selected) {
|
|
424
|
+
if (this.required && selected.length === 0) {
|
|
425
|
+
return `Please select at least one option.
|
|
426
|
+
${color.reset(
|
|
427
|
+
color.dim(
|
|
428
|
+
`Press ${color.gray(
|
|
429
|
+
color.bgWhite(color.inverse(" space "))
|
|
430
|
+
)} to select, ${color.gray(
|
|
431
|
+
color.bgWhite(color.inverse(" enter "))
|
|
432
|
+
)} to submit`
|
|
433
|
+
)
|
|
434
|
+
)}`;
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
render() {
|
|
438
|
+
const title = `${color.gray(S_BAR)}
|
|
444
439
|
${symbol(this.state)} ${opts.message}
|
|
445
440
|
`;
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
441
|
+
switch (this.state) {
|
|
442
|
+
case "submit": {
|
|
443
|
+
return `${title}${color.gray(S_BAR)} ${this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(color.dim(", "))}`;
|
|
444
|
+
}
|
|
445
|
+
case "cancel": {
|
|
446
|
+
const label = this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "cancelled")).join(color.dim(", "));
|
|
447
|
+
return `${title}${color.gray(S_BAR)} ${label.trim() ? `${label}
|
|
448
|
+
${color.gray(S_BAR)}` : ""}`;
|
|
449
|
+
}
|
|
450
|
+
case "error": {
|
|
451
|
+
const footer = this.error.split("\n").map(
|
|
452
|
+
(ln, i) => i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`
|
|
453
|
+
).join("\n");
|
|
454
|
+
return `${title}${color.yellow(S_BAR)} ${this.options.map((option, i, options) => {
|
|
455
|
+
const selected = this.value.includes(option.value) || option.group === true && this.isGroupSelected(`${option.value}`);
|
|
456
|
+
const active = i === this.cursor;
|
|
457
|
+
const groupActive = !active && typeof option.group === "string" && this.options[this.cursor]?.value === option.group;
|
|
458
|
+
if (groupActive) {
|
|
459
|
+
return opt(
|
|
460
|
+
option,
|
|
461
|
+
selected ? "group-active-selected" : "group-active",
|
|
462
|
+
options
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
if (active && selected) {
|
|
466
|
+
return opt(option, "active-selected", options);
|
|
464
467
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
.map((ln, i) => !i ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`)
|
|
471
|
-
.join('\n');
|
|
472
|
-
|
|
473
|
-
return `${title}${color.yellow(S_BAR)} ${this
|
|
474
|
-
.options
|
|
475
|
-
.map((option, i, options) => {
|
|
476
|
-
const selected = this.value.includes(option.value) || option.group && this.isGroupSelected(String(option.value));
|
|
477
|
-
const active = i === this.cursor;
|
|
478
|
-
const groupActive = !active && isString(option.group) && this.options[this.cursor]?.value === option.group;
|
|
479
|
-
|
|
480
|
-
if (groupActive) {
|
|
481
|
-
return opt(option, selected ? 'group-active-selected' : 'group-active', options);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (active && selected) {
|
|
485
|
-
return opt(option, 'active-selected', options);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
if (selected) {
|
|
489
|
-
return opt(option, 'selected', options);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return opt(option, active ? 'active' : 'inactive', options);
|
|
493
|
-
})
|
|
494
|
-
.join(`
|
|
468
|
+
if (selected) {
|
|
469
|
+
return opt(option, "selected", options);
|
|
470
|
+
}
|
|
471
|
+
return opt(option, active ? "active" : "inactive", options);
|
|
472
|
+
}).join(`
|
|
495
473
|
${color.yellow(S_BAR)} `)}
|
|
496
474
|
${footer}
|
|
497
475
|
`;
|
|
476
|
+
}
|
|
477
|
+
default: {
|
|
478
|
+
return `${title}${color.cyan(S_BAR)} ${this.options.map((option, i, options) => {
|
|
479
|
+
const selected = this.value.includes(option.value) || option.group === true && this.isGroupSelected(`${option.value}`);
|
|
480
|
+
const active = i === this.cursor;
|
|
481
|
+
const groupActive = !active && typeof option.group === "string" && this.options[this.cursor]?.value === option.group;
|
|
482
|
+
if (groupActive) {
|
|
483
|
+
return opt(
|
|
484
|
+
option,
|
|
485
|
+
selected ? "group-active-selected" : "group-active",
|
|
486
|
+
options
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
if (active && selected) {
|
|
490
|
+
return opt(option, "active-selected", options);
|
|
498
491
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const selected = this.value.includes(option.value) || option.group && this.isGroupSelected(String(option.value));
|
|
505
|
-
const active = i === this.cursor;
|
|
506
|
-
const groupActive = !active && isString(option.group) && this.options[this.cursor]?.value === option.group;
|
|
507
|
-
|
|
508
|
-
if (groupActive) {
|
|
509
|
-
return opt(option, selected ? 'group-active-selected' : 'group-active', options);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (active && selected) {
|
|
513
|
-
return opt(option, 'active-selected', options);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
if (selected) {
|
|
517
|
-
return opt(option, 'selected', options);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
return opt(option, active ? 'active' : 'inactive', options);
|
|
521
|
-
})
|
|
522
|
-
.join(`
|
|
492
|
+
if (selected) {
|
|
493
|
+
return opt(option, "selected", options);
|
|
494
|
+
}
|
|
495
|
+
return opt(option, active ? "active" : "inactive", options);
|
|
496
|
+
}).join(`
|
|
523
497
|
${color.cyan(S_BAR)} `)}
|
|
524
498
|
${color.cyan(S_BAR_END)}
|
|
525
499
|
`;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}).prompt();
|
|
529
504
|
};
|
|
530
|
-
const strip = (str) => str.replace(ansiRegex(),
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const lines = `
|
|
505
|
+
const strip = (str) => str.replace(ansiRegex(), "");
|
|
506
|
+
export const note = (message = "", title = "") => {
|
|
507
|
+
const lines = `
|
|
534
508
|
${message}
|
|
535
|
-
`.split(
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}, 0),
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
509
|
+
`.split("\n");
|
|
510
|
+
const len = Math.max(
|
|
511
|
+
lines.reduce((sum, ln) => {
|
|
512
|
+
ln = strip(ln);
|
|
513
|
+
return ln.length > sum ? ln.length : sum;
|
|
514
|
+
}, 0),
|
|
515
|
+
strip(title).length
|
|
516
|
+
) + 2;
|
|
517
|
+
const msg = lines.map(
|
|
518
|
+
(ln) => `${color.gray(S_BAR)} ${color.dim(ln)}${" ".repeat(
|
|
519
|
+
len - strip(ln).length
|
|
520
|
+
)}${color.gray(S_BAR)}`
|
|
521
|
+
).join("\n");
|
|
522
|
+
process.stdout.write(
|
|
523
|
+
`${color.gray(S_BAR)}
|
|
524
|
+
${color.green(S_STEP_SUBMIT)} ${color.reset(
|
|
525
|
+
title
|
|
526
|
+
)} ${color.gray(
|
|
527
|
+
S_BAR_H.repeat(Math.max(len - title.length - 1, 1)) + S_CORNER_TOP_RIGHT
|
|
528
|
+
)}
|
|
548
529
|
${msg}
|
|
549
|
-
${color.gray(
|
|
550
|
-
|
|
530
|
+
${color.gray(
|
|
531
|
+
S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT
|
|
532
|
+
)}
|
|
533
|
+
`
|
|
534
|
+
);
|
|
551
535
|
};
|
|
552
|
-
export const cancel = (message =
|
|
553
|
-
|
|
536
|
+
export const cancel = (message = "") => {
|
|
537
|
+
process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
|
|
554
538
|
|
|
555
539
|
`);
|
|
556
540
|
};
|
|
557
|
-
export const intro = (title =
|
|
558
|
-
|
|
541
|
+
export const intro = (title = "") => {
|
|
542
|
+
process.stdout.write(`${color.gray(S_BAR_START)} ${title}
|
|
559
543
|
`);
|
|
560
544
|
};
|
|
561
|
-
export const outro = (message =
|
|
562
|
-
|
|
545
|
+
export const outro = (message = "") => {
|
|
546
|
+
process.stdout.write(
|
|
547
|
+
`${color.gray(S_BAR)}
|
|
563
548
|
${color.gray(S_BAR_END)} ${message}
|
|
564
549
|
|
|
565
|
-
`
|
|
550
|
+
`
|
|
551
|
+
);
|
|
566
552
|
};
|
|
567
553
|
export const log = {
|
|
568
|
-
|
|
569
|
-
/**
|
|
554
|
+
/**
|
|
570
555
|
* Logs an message, prefixed with a gray bar.
|
|
571
556
|
* @param {string} message - The message to log.
|
|
572
557
|
* @param {LogMessageOptions} [opts] - Optional settings for the log message. See {@link LogMessageOptions}.
|
|
573
558
|
*/
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
559
|
+
message: (message = "", { symbol: symbol2 = color.gray(S_BAR) } = {}) => {
|
|
560
|
+
const parts = [color.gray(S_BAR)];
|
|
561
|
+
if (message) {
|
|
562
|
+
const [firstLine, ...lines] = message.split("\n");
|
|
563
|
+
parts.push(
|
|
564
|
+
`${symbol2} ${firstLine}`,
|
|
565
|
+
...lines.map((ln) => `${color.gray(S_BAR)} ${ln}`)
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
process.stdout.write(`${parts.join("\n")}
|
|
584
569
|
`);
|
|
585
|
-
|
|
570
|
+
},
|
|
586
571
|
info: (message) => {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
});
|
|
590
|
-
},
|
|
572
|
+
log.message(message, { symbol: color.blue(S_INFO) });
|
|
573
|
+
},
|
|
591
574
|
success: (message) => {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
});
|
|
595
|
-
},
|
|
575
|
+
log.message(message, { symbol: color.green(S_SUCCESS) });
|
|
576
|
+
},
|
|
596
577
|
step: (message) => {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
});
|
|
600
|
-
},
|
|
578
|
+
log.message(message, { symbol: color.green(S_STEP_SUBMIT) });
|
|
579
|
+
},
|
|
601
580
|
warn: (message) => {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
});
|
|
605
|
-
},
|
|
581
|
+
log.message(message, { symbol: color.yellow(S_WARN) });
|
|
582
|
+
},
|
|
606
583
|
warning: (message) => {
|
|
607
|
-
|
|
608
|
-
|
|
584
|
+
log.warn(message);
|
|
585
|
+
},
|
|
609
586
|
error: (message) => {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
});
|
|
613
|
-
},
|
|
587
|
+
log.message(message, { symbol: color.red(S_ERROR) });
|
|
588
|
+
}
|
|
614
589
|
};
|
|
615
|
-
const frames = unicode ? [
|
|
616
|
-
'\u25D2',
|
|
617
|
-
'\u25D0',
|
|
618
|
-
'\u25D3',
|
|
619
|
-
'\u25D1',
|
|
620
|
-
] : [
|
|
621
|
-
'\u2022',
|
|
622
|
-
'o',
|
|
623
|
-
'O',
|
|
624
|
-
'0',
|
|
625
|
-
];
|
|
626
|
-
|
|
590
|
+
const frames = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"];
|
|
627
591
|
export const spinner = () => {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
${color.magenta(
|
|
638
|
-
`
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
592
|
+
let unblock;
|
|
593
|
+
let loop;
|
|
594
|
+
const delay = unicode ? 80 : 120;
|
|
595
|
+
return {
|
|
596
|
+
start(message = "") {
|
|
597
|
+
message = message.replace(/\.?\.?\.$/, "");
|
|
598
|
+
unblock = block();
|
|
599
|
+
process.stdout.write(
|
|
600
|
+
`${color.gray(S_BAR)}
|
|
601
|
+
${color.magenta("\u25CB")} ${message}
|
|
602
|
+
`
|
|
603
|
+
);
|
|
604
|
+
let i = 0;
|
|
605
|
+
let dot = 0;
|
|
606
|
+
loop = setInterval(() => {
|
|
607
|
+
const frame = frames[i];
|
|
608
|
+
process.stdout.write(cursor.move(-999, -1));
|
|
609
|
+
process.stdout.write(
|
|
610
|
+
`${color.magenta(frame)} ${message}${Math.floor(dot) >= 1 ? ".".repeat(Math.floor(dot)).slice(0, 3) : ""}
|
|
611
|
+
`
|
|
612
|
+
);
|
|
613
|
+
i = i === frames.length - 1 ? 0 : i + 1;
|
|
614
|
+
dot = dot === frames.length ? 0 : dot + 0.125;
|
|
615
|
+
}, delay);
|
|
616
|
+
},
|
|
617
|
+
stop(message = "") {
|
|
618
|
+
process.stdout.write(cursor.move(-999, -2));
|
|
619
|
+
process.stdout.write(erase.down(2));
|
|
620
|
+
clearInterval(loop);
|
|
621
|
+
process.stdout.write(
|
|
622
|
+
`${color.gray(S_BAR)}
|
|
658
623
|
${color.green(S_STEP_SUBMIT)} ${message}
|
|
659
|
-
`
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
}
|
|
624
|
+
`
|
|
625
|
+
);
|
|
626
|
+
unblock();
|
|
627
|
+
}
|
|
628
|
+
};
|
|
663
629
|
};
|
|
664
630
|
function ansiRegex() {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
return new RegExp(pattern, 'g');
|
|
631
|
+
const pattern = [
|
|
632
|
+
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
|
|
633
|
+
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`
|
|
634
|
+
].join("|");
|
|
635
|
+
return new RegExp(pattern, "g");
|
|
671
636
|
}
|
|
672
|
-
|
|
673
637
|
export const group = async (prompts, opts) => {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
if (typeof opts?.onCancel === 'function' && isCancel(result)) {
|
|
686
|
-
results[name] = 'canceled';
|
|
687
|
-
opts.onCancel({
|
|
688
|
-
results,
|
|
689
|
-
});
|
|
690
|
-
continue;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
results[name] = result;
|
|
638
|
+
const results = {};
|
|
639
|
+
const promptNames = Object.keys(prompts);
|
|
640
|
+
for (const name of promptNames) {
|
|
641
|
+
const prompt = prompts[name];
|
|
642
|
+
const result = await prompt({ results })?.catch((e) => {
|
|
643
|
+
throw e;
|
|
644
|
+
});
|
|
645
|
+
if (typeof opts?.onCancel === "function" && isCancel(result)) {
|
|
646
|
+
results[name] = "canceled";
|
|
647
|
+
opts.onCancel({ results });
|
|
648
|
+
continue;
|
|
694
649
|
}
|
|
695
|
-
|
|
696
|
-
|
|
650
|
+
results[name] = result;
|
|
651
|
+
}
|
|
652
|
+
return results;
|
|
697
653
|
};
|