@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,111 +1,144 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { stdin as input, stdout as output } from "node:process";
|
|
3
|
-
import readline from "node:readline/promises";
|
|
4
|
-
import { colorize } from "../../utils/colorize.js";
|
|
5
|
-
import { bar, fmt, msg } from "../../utils/messages.js";
|
|
1
|
+
import {Value} from '@sinclair/typebox/value';
|
|
6
2
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
stdin as input,
|
|
4
|
+
stdout as output,
|
|
5
|
+
} from 'node:process';
|
|
6
|
+
import readline from 'node:readline/promises';
|
|
7
|
+
import {colorize} from '../../utils/colorize.js';
|
|
8
|
+
import {
|
|
9
|
+
bar,
|
|
10
|
+
fmt,
|
|
11
|
+
msg,
|
|
12
|
+
} from '../../utils/messages.js';
|
|
13
|
+
import {
|
|
14
|
+
countLines,
|
|
15
|
+
deleteLastLine,
|
|
16
|
+
deleteLastLines,
|
|
17
|
+
} from '../../utils/terminal.js';
|
|
18
|
+
|
|
11
19
|
export async function multiselectPrompt(options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
titleVariant,
|
|
20
|
-
hint,
|
|
21
|
-
content,
|
|
22
|
-
contentColor = "dim",
|
|
23
|
-
contentTypography,
|
|
24
|
-
contentVariant,
|
|
25
|
-
borderColor = "viceGradient",
|
|
26
|
-
variantOptions
|
|
27
|
-
} = options;
|
|
28
|
-
if (!choices || choices.length === 0) {
|
|
29
|
-
throw new Error("Choices are required for multiselect prompt.");
|
|
30
|
-
}
|
|
31
|
-
const rl = readline.createInterface({ input, output });
|
|
32
|
-
const formattedBar = bar({ borderColor });
|
|
33
|
-
let linesToDelete = 0;
|
|
34
|
-
let errorMessage = "";
|
|
35
|
-
try {
|
|
36
|
-
while (true) {
|
|
37
|
-
if (linesToDelete > 0) {
|
|
38
|
-
deleteLastLines(linesToDelete);
|
|
39
|
-
}
|
|
40
|
-
const question = fmt({
|
|
41
|
-
type: errorMessage !== "" ? "M_ERROR" : "M_GENERAL",
|
|
42
|
-
title: `${title}${defaultValue ? ` [Default: ${Array.isArray(defaultValue) ? defaultValue.join(", ") : defaultValue}]` : ""}`,
|
|
43
|
-
titleColor,
|
|
44
|
-
titleTypography,
|
|
20
|
+
const {
|
|
21
|
+
title,
|
|
22
|
+
choices,
|
|
23
|
+
schema,
|
|
24
|
+
defaultValue,
|
|
25
|
+
titleColor = 'cyanBright',
|
|
26
|
+
titleTypography = 'bold',
|
|
45
27
|
titleVariant,
|
|
28
|
+
hint,
|
|
46
29
|
content,
|
|
47
|
-
contentColor,
|
|
30
|
+
contentColor = 'dim',
|
|
48
31
|
contentTypography,
|
|
49
32
|
contentVariant,
|
|
50
|
-
borderColor,
|
|
51
|
-
hint,
|
|
33
|
+
borderColor = 'viceGradient',
|
|
52
34
|
variantOptions,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
35
|
+
} = options;
|
|
36
|
+
|
|
37
|
+
if (!choices || !choices.length) {
|
|
38
|
+
throw Error('Choices are required for multiselect prompt.');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const rl = readline.createInterface({
|
|
42
|
+
input,
|
|
43
|
+
output,
|
|
44
|
+
});
|
|
45
|
+
const formattedBar = bar({
|
|
46
|
+
borderColor,
|
|
47
|
+
});
|
|
48
|
+
let linesToDelete = 0;
|
|
49
|
+
let errorMessage = '';
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
while (true) {
|
|
53
|
+
if (linesToDelete > 0) {
|
|
54
|
+
deleteLastLines(linesToDelete);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const question = fmt({
|
|
58
|
+
type: errorMessage !== '' ? 'M_ERROR' : 'M_GENERAL',
|
|
59
|
+
title: `${title}${defaultValue ? ` [Default: ${Array.isArray(defaultValue) ? defaultValue.join(', ') : defaultValue}]` : ''}`,
|
|
60
|
+
titleColor,
|
|
61
|
+
titleTypography,
|
|
62
|
+
titleVariant,
|
|
63
|
+
content,
|
|
64
|
+
contentColor,
|
|
65
|
+
contentTypography,
|
|
66
|
+
contentVariant,
|
|
67
|
+
borderColor,
|
|
68
|
+
hint,
|
|
69
|
+
variantOptions,
|
|
70
|
+
errorMessage,
|
|
71
|
+
addNewLineBefore: false,
|
|
72
|
+
addNewLineAfter: false,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const choicesText = choices
|
|
76
|
+
.map((choice, index) => `${formattedBar} ${index + 1}) ${choice.title}${choice.description ? ` - ${choice.description}` : ''}`)
|
|
77
|
+
.join('\n');
|
|
78
|
+
|
|
79
|
+
const fullPrompt = `${question}
|
|
61
80
|
${choicesText}
|
|
62
81
|
${formattedBar} ${colorize(`Enter your choices (comma-separated numbers between 1-${choices.length})`, contentColor)}:
|
|
63
82
|
${formattedBar} `;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
|
|
84
|
+
const formattedPrompt = fmt({
|
|
85
|
+
type: 'M_NULL',
|
|
86
|
+
title: fullPrompt,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const questionLines = countLines(formattedPrompt);
|
|
90
|
+
|
|
91
|
+
linesToDelete = questionLines + 1;
|
|
92
|
+
const answer = (await rl.question(formattedPrompt)).trim();
|
|
93
|
+
|
|
94
|
+
if (!answer && defaultValue !== void 0) {
|
|
95
|
+
deleteLastLine();
|
|
96
|
+
msg({
|
|
97
|
+
type: 'M_MIDDLE',
|
|
98
|
+
title: ` ${Array.isArray(defaultValue) ? defaultValue.join(', ') : defaultValue}`,
|
|
99
|
+
titleColor: 'none',
|
|
100
|
+
});
|
|
101
|
+
msg({
|
|
102
|
+
type: 'M_NEWLINE',
|
|
103
|
+
});
|
|
104
|
+
return defaultValue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const selections = answer
|
|
108
|
+
.split(',')
|
|
109
|
+
.map((s) => s.trim());
|
|
110
|
+
|
|
111
|
+
const invalidSelections = selections.filter((s) => {
|
|
112
|
+
const num = Number(s);
|
|
113
|
+
return isNaN(num) || num < 1 || num > choices.length;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (invalidSelections.length > 0) {
|
|
117
|
+
errorMessage = `Invalid selections: ${invalidSelections.join(', ')}. Please enter numbers between 1 and ${choices.length}.`;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const selectedValues = selections.map((s) => choices[Number(s) - 1]?.id);
|
|
122
|
+
let isValid = true;
|
|
123
|
+
|
|
124
|
+
errorMessage = '';
|
|
125
|
+
if (schema) {
|
|
126
|
+
isValid = Value.Check(schema, selectedValues);
|
|
127
|
+
if (!isValid) {
|
|
128
|
+
const errors = Value.Errors(schema, selectedValues);
|
|
129
|
+
errorMessage = errors.length > 0 ? errors[0]?.message ?? 'Invalid input.' : 'Invalid input.';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isValid) {
|
|
134
|
+
msg({
|
|
135
|
+
type: 'M_NEWLINE',
|
|
136
|
+
});
|
|
137
|
+
rl.close();
|
|
138
|
+
return selectedValues;
|
|
139
|
+
}
|
|
100
140
|
}
|
|
101
|
-
|
|
102
|
-
if (isValid) {
|
|
103
|
-
msg({ type: "M_NEWLINE" });
|
|
141
|
+
} finally {
|
|
104
142
|
rl.close();
|
|
105
|
-
return selectedValues;
|
|
106
|
-
}
|
|
107
143
|
}
|
|
108
|
-
} finally {
|
|
109
|
-
rl.close();
|
|
110
|
-
}
|
|
111
144
|
}
|
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
import Prompt from
|
|
1
|
+
import Prompt from '../../components/prompts/prompt.js';
|
|
2
|
+
|
|
2
3
|
export default class MultiSelectPrompt extends Prompt {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
4
|
+
options;
|
|
5
|
+
cursor = 0;
|
|
6
|
+
get _value() {
|
|
7
|
+
return this.options[this.cursor].value;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
toggleAll() {
|
|
11
|
+
const allSelected = this.value.length === this.options.length;
|
|
12
|
+
this.value = allSelected ? [] : this.options.map((v) => v.value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
toggleValue() {
|
|
16
|
+
const selected = this.value.includes(this._value);
|
|
17
|
+
this.value = selected ? this.value.filter((value) => value !== this._value) : [
|
|
18
|
+
...this.value,
|
|
19
|
+
this._value,
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
super(opts, false);
|
|
25
|
+
this.options = opts.options;
|
|
26
|
+
this.value = opts.initialValues ?? [].slice();
|
|
27
|
+
this.cursor = Math.max(this.options.findIndex(({value}) => value === opts.cursorAt), 0);
|
|
28
|
+
this.on('key', (char) => {
|
|
29
|
+
if (char === 'a') {
|
|
30
|
+
this.toggleAll();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.on('cursor', (key) => {
|
|
34
|
+
switch(key) {
|
|
35
|
+
case 'left':
|
|
36
|
+
case 'up':
|
|
37
|
+
this.cursor = !this.cursor ? this.options.length - 1 : this.cursor - 1;
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
case 'down':
|
|
41
|
+
case 'right':
|
|
42
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
case 'space':
|
|
46
|
+
this.toggleValue();
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
45
51
|
}
|
|
@@ -1,127 +1,153 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
import process, {
|
|
2
|
+
stdin as input,
|
|
3
|
+
stdout as output,
|
|
4
|
+
} from 'node:process';
|
|
5
|
+
import readline from 'node:readline';
|
|
6
|
+
import {
|
|
7
|
+
cyanBright,
|
|
8
|
+
dim,
|
|
9
|
+
greenBright,
|
|
10
|
+
redBright,
|
|
11
|
+
} from 'picocolors';
|
|
12
|
+
import {colorize} from '../../mod.js';
|
|
13
|
+
import {
|
|
14
|
+
bar,
|
|
15
|
+
symbols,
|
|
16
|
+
msg,
|
|
17
|
+
} from '../../utils/messages.js';
|
|
18
|
+
import {deleteLastLine} from '../../utils/terminal.js';
|
|
19
|
+
|
|
20
|
+
export function multiselectPrompt(params) {
|
|
21
|
+
const {
|
|
22
|
+
title,
|
|
23
|
+
options,
|
|
24
|
+
required = false,
|
|
25
|
+
initial = [],
|
|
26
|
+
borderColor = 'viceGradient',
|
|
27
|
+
titleColor = 'cyanBright',
|
|
28
|
+
titleTypography = 'bold',
|
|
29
|
+
titleVariant,
|
|
30
|
+
border = true,
|
|
31
|
+
endTitle = '\u{1F44B}',
|
|
32
|
+
endTitleColor = 'passionGradient',
|
|
33
|
+
} = params;
|
|
34
|
+
|
|
35
|
+
let pointer = 0;
|
|
36
|
+
const selectedOptions = new Set(initial
|
|
37
|
+
.map((opt) => options.findIndex((o) => o.value === opt))
|
|
38
|
+
.filter((i) => i >= 0));
|
|
39
|
+
|
|
40
|
+
const rl = readline.createInterface({
|
|
41
|
+
input,
|
|
42
|
+
output,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
readline.emitKeypressEvents(input, rl);
|
|
46
|
+
input.setRawMode?.(true);
|
|
47
|
+
const formattedBar = bar({
|
|
48
|
+
borderColor,
|
|
49
|
+
});
|
|
50
|
+
let linesRendered = 0;
|
|
51
|
+
const instructions = `Use <\u2191/\u2193> or <k/j> to navigate, <Space> to select/deselect, <Enter> to confirm, <Ctrl+C> to exit`;
|
|
52
|
+
let errorMessage = '';
|
|
53
|
+
|
|
54
|
+
function renderOptions() {
|
|
55
|
+
if (linesRendered > 0) {
|
|
56
|
+
process.stdout.write(`\x1B[${linesRendered}A`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let outputStr = `${greenBright(symbols.step_active)} ${colorize(title, titleColor, titleTypography)}
|
|
39
60
|
`;
|
|
40
|
-
|
|
41
|
-
|
|
61
|
+
|
|
62
|
+
if (errorMessage) {
|
|
63
|
+
outputStr += redBright(`${symbols.step_error} ${errorMessage}
|
|
42
64
|
`);
|
|
43
|
-
} else {
|
|
44
|
-
outputStr += `${formattedBar} ${dim(instructions)}
|
|
45
|
-
`;
|
|
46
|
-
}
|
|
47
|
-
options.forEach((option, index) => {
|
|
48
|
-
const isSelected = selectedOptions.has(index);
|
|
49
|
-
const isHighlighted = index === pointer;
|
|
50
|
-
const checkbox = isSelected ? "[x]" : "[ ]";
|
|
51
|
-
const prefix = isHighlighted ? "> " : " ";
|
|
52
|
-
const optionLabel = isHighlighted ? cyanBright(option.value) : option.value;
|
|
53
|
-
const hint = option.hint ? ` (${option.hint})` : "";
|
|
54
|
-
outputStr += `${formattedBar} ${prefix}${checkbox} ${optionLabel}${dim(hint)}
|
|
55
|
-
`;
|
|
56
|
-
});
|
|
57
|
-
process.stdout.write(outputStr);
|
|
58
|
-
linesRendered = 1 + 1 + options.length;
|
|
59
|
-
}
|
|
60
|
-
renderOptions();
|
|
61
|
-
return new Promise((resolve) => {
|
|
62
|
-
function onKeyPress(str, key) {
|
|
63
|
-
if (key.name === "up" || key.name === "k") {
|
|
64
|
-
pointer = (pointer - 1 + options.length) % options.length;
|
|
65
|
-
errorMessage = "";
|
|
66
|
-
renderOptions();
|
|
67
|
-
} else if (key.name === "down" || key.name === "j") {
|
|
68
|
-
pointer = (pointer + 1) % options.length;
|
|
69
|
-
errorMessage = "";
|
|
70
|
-
renderOptions();
|
|
71
|
-
} else if (key.name === "space") {
|
|
72
|
-
if (selectedOptions.has(pointer)) {
|
|
73
|
-
selectedOptions.delete(pointer);
|
|
74
65
|
} else {
|
|
75
|
-
|
|
66
|
+
outputStr += `${formattedBar} ${dim(instructions)}
|
|
67
|
+
`;
|
|
76
68
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
msg({
|
|
89
|
-
type: "M_MIDDLE"
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
deleteLastLine();
|
|
93
|
-
errorMessage = "You must select at least one option.\x1B[K";
|
|
94
|
-
renderOptions();
|
|
69
|
+
|
|
70
|
+
for (const [index, option] of options.entries()) {
|
|
71
|
+
const isSelected = selectedOptions.has(index);
|
|
72
|
+
const isHighlighted = index === pointer;
|
|
73
|
+
const checkbox = isSelected ? '[x]' : '[ ]';
|
|
74
|
+
const prefix = isHighlighted ? '> ' : ' ';
|
|
75
|
+
const optionLabel = isHighlighted ? cyanBright(option.value) : option.value;
|
|
76
|
+
const hint = option.hint ? ` (${option.hint})` : '';
|
|
77
|
+
|
|
78
|
+
outputStr += `${formattedBar} ${prefix}${checkbox} ${optionLabel}${dim(hint)}
|
|
79
|
+
`;
|
|
95
80
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
msg({
|
|
101
|
-
type: "M_END",
|
|
102
|
-
title: endTitle,
|
|
103
|
-
titleColor: endTitleColor,
|
|
104
|
-
titleTypography,
|
|
105
|
-
titleVariant,
|
|
106
|
-
border,
|
|
107
|
-
borderColor
|
|
108
|
-
});
|
|
109
|
-
cleanup(true);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function cleanup(isCtrlC = false) {
|
|
113
|
-
if (typeof input.setRawMode === "function") {
|
|
114
|
-
input.setRawMode(false);
|
|
115
|
-
}
|
|
116
|
-
rl.close();
|
|
117
|
-
input.removeListener("keypress", onKeyPress);
|
|
118
|
-
process.stdout.write(`\x1B[${linesRendered}B`);
|
|
119
|
-
if (isCtrlC) {
|
|
120
|
-
process.exit();
|
|
121
|
-
} else {
|
|
122
|
-
console.log();
|
|
123
|
-
}
|
|
81
|
+
|
|
82
|
+
process.stdout.write(outputStr);
|
|
83
|
+
linesRendered = 1 + 1 + options.length;
|
|
124
84
|
}
|
|
125
|
-
|
|
126
|
-
|
|
85
|
+
|
|
86
|
+
renderOptions();
|
|
87
|
+
return new Promise((resolve) => {
|
|
88
|
+
function onKeyPress(str, key) {
|
|
89
|
+
if (key.name === 'up' || key.name === 'k') {
|
|
90
|
+
pointer = (pointer - 1 + options.length) % options.length;
|
|
91
|
+
errorMessage = '';
|
|
92
|
+
renderOptions();
|
|
93
|
+
} else if (key.name === 'down' || key.name === 'j') {
|
|
94
|
+
pointer = (pointer + 1) % options.length;
|
|
95
|
+
errorMessage = '';
|
|
96
|
+
renderOptions();
|
|
97
|
+
} else if (key.name === 'space') {
|
|
98
|
+
if (selectedOptions.has(pointer)) {
|
|
99
|
+
selectedOptions.delete(pointer);
|
|
100
|
+
} else {
|
|
101
|
+
selectedOptions.add(pointer);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
errorMessage = '';
|
|
105
|
+
renderOptions();
|
|
106
|
+
} else if (key.name === 'return') {
|
|
107
|
+
if (!required || selectedOptions.size > 0) {
|
|
108
|
+
const selectedValues = Array
|
|
109
|
+
.from(selectedOptions)
|
|
110
|
+
.map((index) => options[index].value);
|
|
111
|
+
|
|
112
|
+
cleanup();
|
|
113
|
+
resolve(selectedValues);
|
|
114
|
+
deleteLastLine();
|
|
115
|
+
deleteLastLine();
|
|
116
|
+
msg({
|
|
117
|
+
type: 'M_MIDDLE',
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
deleteLastLine();
|
|
121
|
+
errorMessage = 'You must select at least one option.\x1B[K';
|
|
122
|
+
renderOptions();
|
|
123
|
+
}
|
|
124
|
+
} else if (key.name === 'c' && key.ctrl) {
|
|
125
|
+
msg({
|
|
126
|
+
type: 'M_NEWLINE',
|
|
127
|
+
});
|
|
128
|
+
msg({
|
|
129
|
+
type: 'M_END',
|
|
130
|
+
title: endTitle,
|
|
131
|
+
titleColor: endTitleColor,
|
|
132
|
+
titleTypography,
|
|
133
|
+
titleVariant,
|
|
134
|
+
border,
|
|
135
|
+
borderColor,
|
|
136
|
+
});
|
|
137
|
+
cleanup();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function cleanup() {
|
|
145
|
+
input.setRawMode?.(false);
|
|
146
|
+
rl.close();
|
|
147
|
+
input.removeListener('keypress', onKeyPress);
|
|
148
|
+
process.stdout.write(`\x1B[${linesRendered}B`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
input.on('keypress', onKeyPress);
|
|
152
|
+
});
|
|
127
153
|
}
|