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