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