@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,56 +1,59 @@
|
|
|
1
|
+
const isString = (a) => typeof a === 'string';
|
|
2
|
+
|
|
1
3
|
export class BrowserReporter {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
_getLogFn(level) {
|
|
23
|
-
if (level < 1) {
|
|
24
|
-
return console.__error || console.error;
|
|
4
|
+
options;
|
|
5
|
+
defaultColor;
|
|
6
|
+
levelColorMap;
|
|
7
|
+
typeColorMap;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = {...options};
|
|
10
|
+
this.defaultColor = '#7f8c8d';
|
|
11
|
+
this.levelColorMap = {
|
|
12
|
+
0: '#c0392b',
|
|
13
|
+
|
|
14
|
+
1: '#f39c12',
|
|
15
|
+
|
|
16
|
+
3: '#00BCD4',
|
|
17
|
+
};
|
|
18
|
+
this.typeColorMap = {
|
|
19
|
+
success: '#2ecc71',
|
|
20
|
+
};
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
|
|
23
|
+
_getLogFn(level) {
|
|
24
|
+
if (level < 1) {
|
|
25
|
+
return console.__error || console.error;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (level === 1) {
|
|
29
|
+
return console.__warn || console.warn;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return console.__log || console.log;
|
|
28
33
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
|
|
35
|
+
log(logObj) {
|
|
36
|
+
const consoleLogFn = this._getLogFn(logObj.level);
|
|
37
|
+
const type = logObj.type === 'log' ? '' : logObj.type;
|
|
38
|
+
const tag = logObj.tag || '';
|
|
39
|
+
const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
|
|
40
|
+
|
|
41
|
+
const style = `
|
|
37
42
|
background: ${color};
|
|
38
43
|
border-radius: 0.5em;
|
|
39
44
|
color: white;
|
|
40
45
|
font-weight: bold;
|
|
41
46
|
padding: 2px 0.5em;
|
|
42
47
|
`;
|
|
43
|
-
const badge = `%c${[tag, type].filter(Boolean).join(":")}`;
|
|
44
|
-
if (typeof logObj.args[0] === "string") {
|
|
45
|
-
consoleLogFn(
|
|
46
|
-
`${badge}%c ${logObj.args[0]}`,
|
|
47
|
-
style,
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const badge = `%c${[tag, type]
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.join(':')}`;
|
|
52
|
+
|
|
53
|
+
if (isString(logObj.args[0])) {
|
|
54
|
+
consoleLogFn(`${badge}%c ${logObj.args[0]}`, style, '', ...logObj.args.slice(1));
|
|
55
|
+
} else {
|
|
56
|
+
consoleLogFn(badge, style, ...logObj.args);
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
|
-
}
|
|
56
59
|
}
|
|
@@ -1,101 +1,114 @@
|
|
|
1
|
-
import isUnicodeSupported from
|
|
2
|
-
import _stringWidth from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import isUnicodeSupported from 'is-unicode-supported';
|
|
2
|
+
import _stringWidth from 'string-width';
|
|
3
|
+
import {box} from '../../../utils/box.js';
|
|
4
|
+
import {colors} from '../../../utils/color.js';
|
|
5
|
+
import {parseStack} from '../../../utils/error.js';
|
|
6
|
+
import {stripAnsi} from '../../../utils/utils.js';
|
|
7
|
+
import {BasicReporter} from './basic.js';
|
|
8
|
+
|
|
9
|
+
const isString = (a) => typeof a === 'string';
|
|
10
|
+
|
|
8
11
|
export const TYPE_COLOR_MAP = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
info: 'cyan',
|
|
13
|
+
fail: 'red',
|
|
14
|
+
success: 'green',
|
|
15
|
+
ready: 'green',
|
|
16
|
+
start: 'magenta',
|
|
14
17
|
};
|
|
15
18
|
export const LEVEL_COLOR_MAP = {
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
0: 'red',
|
|
20
|
+
1: 'yellow',
|
|
18
21
|
};
|
|
19
22
|
const unicode = isUnicodeSupported();
|
|
20
23
|
const s = (c, fallback) => unicode ? c : fallback;
|
|
24
|
+
|
|
21
25
|
const TYPE_ICONS = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
error: s('\u2716', '\xD7'),
|
|
27
|
+
fatal: s('\u2716', '\xD7'),
|
|
28
|
+
ready: s('\u2714', '\u221A'),
|
|
29
|
+
warn: s('\u26A0', '\u203C'),
|
|
30
|
+
info: s('\u2139', 'i'),
|
|
31
|
+
success: s('\u2714', '\u221A'),
|
|
32
|
+
debug: s('\u2699', 'D'),
|
|
33
|
+
trace: s('\u2192', '\u2192'),
|
|
34
|
+
fail: s('\u2716', '\xD7'),
|
|
35
|
+
start: s('\u25D0', 'o'),
|
|
36
|
+
log: '',
|
|
33
37
|
};
|
|
38
|
+
|
|
34
39
|
function stringWidth(str) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
if (!Intl.Segmenter) {
|
|
41
|
+
return stripAnsi(str).length;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return _stringWidth(str);
|
|
39
45
|
}
|
|
46
|
+
|
|
40
47
|
export class FancyReporter extends BasicReporter {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
49
|
-
if (isBadge) {
|
|
50
|
-
return getBgColor(typeColor)(
|
|
51
|
-
colors.black(` ${logObj.type.toUpperCase()} `)
|
|
52
|
-
);
|
|
48
|
+
// @ts-expect-error TODO: fix ts
|
|
49
|
+
formatStack(stack) {
|
|
50
|
+
return '\n' + parseStack(stack)
|
|
51
|
+
.map((line) => ' ' + line
|
|
52
|
+
.replace(/^at +/, (m) => colors.gray(m))
|
|
53
|
+
.replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`))
|
|
54
|
+
.join('\n');
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"\n"
|
|
61
|
-
);
|
|
62
|
-
if (logObj.type === "box") {
|
|
63
|
-
return box(
|
|
64
|
-
characterFormat(
|
|
65
|
-
message + (additional.length > 0 ? "\n" + additional.join("\n") : "")
|
|
66
|
-
),
|
|
67
|
-
{
|
|
68
|
-
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
69
|
-
style: logObj.style
|
|
56
|
+
|
|
57
|
+
formatType(logObj, isBadge) {
|
|
58
|
+
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || 'gray';
|
|
59
|
+
|
|
60
|
+
if (isBadge) {
|
|
61
|
+
return getBgColor(typeColor)(colors.black(` ${logObj.type.toUpperCase()} `));
|
|
70
62
|
}
|
|
71
|
-
|
|
63
|
+
|
|
64
|
+
const _type = isString(TYPE_ICONS[logObj.type]) ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
65
|
+
|
|
66
|
+
return _type ? getColor(typeColor)(_type) : '';
|
|
72
67
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
// @ts-expect-error TODO: fix ts
|
|
69
|
+
formatLogObj(logObj, opts) {
|
|
70
|
+
const [message, ...additional] = this
|
|
71
|
+
.formatArgs(logObj.args, opts)
|
|
72
|
+
.split('\n');
|
|
73
|
+
|
|
74
|
+
if (logObj.type === 'box') {
|
|
75
|
+
return box(characterFormat(message + (additional.length > 0 ? '\n' + additional.join('\n') : '')), {
|
|
76
|
+
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
77
|
+
style: logObj.style,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const date = this.formatDate(logObj.date, opts);
|
|
82
|
+
const coloredDate = date && colors.gray(date);
|
|
83
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
84
|
+
const type = this.formatType(isBadge, opts);
|
|
85
|
+
const tag = logObj.tag ? colors.gray(logObj.tag) : '';
|
|
86
|
+
let line;
|
|
87
|
+
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
88
|
+
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
89
|
+
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
90
|
+
|
|
91
|
+
line = space > 0 && (opts.columns || 0) >= 80 ? left + ' '.repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : '') + left;
|
|
92
|
+
line += characterFormat(additional.length > 0 ? '\n' + additional.join('\n') : '');
|
|
93
|
+
if (logObj.type === 'trace') {
|
|
94
|
+
const _err = Error('Trace: ' + logObj.message);
|
|
95
|
+
line += this.formatStack(_err.stack || '');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return isBadge ? `
|
|
99
|
+
${line}
|
|
100
|
+
` : line;
|
|
89
101
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
102
|
+
}function characterFormat(str) {
|
|
103
|
+
return str
|
|
104
|
+
.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m))
|
|
105
|
+
.replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
95
106
|
}
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
|
|
108
|
+
function getColor(color = 'white') {
|
|
109
|
+
return colors[color] || colors.white;
|
|
98
110
|
}
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
|
|
112
|
+
function getBgColor(color = 'bgWhite') {
|
|
113
|
+
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
101
114
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export {LogLevels, LogTypes} from '../../utils/constants.js';
|
|
2
|
+
export {Relinka} from '../../components/prompts/relinka.js';
|
|
@@ -1,64 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import {confirmPrompt} from '../../components/confirm/confirm-main.js';
|
|
2
|
+
import {datePrompt} from '../../components/date/date.js';
|
|
3
|
+
import {textPrompt} from '../../components/input/text-main.js';
|
|
4
|
+
import {nextStepsPrompt} from '../../components/next-steps/next-steps.js';
|
|
5
|
+
import {numberPrompt} from '../../components/number/number-main.js';
|
|
6
|
+
import {passwordPrompt} from '../../components/password/password-main.js';
|
|
7
|
+
import {numSelectPrompt} from '../../components/select/num-select.js';
|
|
8
|
+
import {endPrompt} from '../../components/st-end/end.js';
|
|
9
|
+
import {startPrompt} from '../../components/st-end/start.js';
|
|
10
|
+
|
|
10
11
|
export async function prompt(options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
break;
|
|
18
|
-
case "text":
|
|
19
|
-
value = await textPrompt(options);
|
|
20
|
-
break;
|
|
21
|
-
case "number":
|
|
22
|
-
value = await numberPrompt(options);
|
|
23
|
-
break;
|
|
24
|
-
case "confirm":
|
|
25
|
-
value = await confirmPrompt(options);
|
|
26
|
-
break;
|
|
27
|
-
case "numSelect":
|
|
28
|
-
value = await numSelectPrompt(options);
|
|
29
|
-
break;
|
|
12
|
+
const {
|
|
13
|
+
type,
|
|
14
|
+
id,
|
|
15
|
+
action,
|
|
16
|
+
} = options;
|
|
17
|
+
let value;
|
|
30
18
|
|
|
19
|
+
switch(type) {
|
|
20
|
+
case 'start':
|
|
21
|
+
await startPrompt(options);
|
|
22
|
+
value = null;
|
|
23
|
+
break;
|
|
31
24
|
|
|
25
|
+
case 'text':
|
|
26
|
+
value = await textPrompt(options);
|
|
27
|
+
break;
|
|
32
28
|
|
|
29
|
+
case 'number':
|
|
30
|
+
value = await numberPrompt(options);
|
|
31
|
+
break;
|
|
33
32
|
|
|
33
|
+
case 'confirm':
|
|
34
|
+
value = await confirmPrompt(options);
|
|
35
|
+
break;
|
|
34
36
|
|
|
37
|
+
case 'numSelect':
|
|
38
|
+
value = await numSelectPrompt(options);
|
|
39
|
+
break;
|
|
35
40
|
|
|
41
|
+
case 'password':
|
|
42
|
+
value = await passwordPrompt(options);
|
|
43
|
+
break;
|
|
36
44
|
|
|
45
|
+
case 'date':
|
|
46
|
+
value = await datePrompt({
|
|
47
|
+
...options,
|
|
48
|
+
dateFormat: 'DD/MM/YYYY',
|
|
49
|
+
dateKind: 'other',
|
|
50
|
+
});
|
|
51
|
+
break;
|
|
37
52
|
|
|
53
|
+
case 'nextSteps':
|
|
54
|
+
await nextStepsPrompt(options);
|
|
55
|
+
value = null;
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'end':
|
|
59
|
+
await endPrompt(options);
|
|
60
|
+
value = null;
|
|
61
|
+
break;
|
|
38
62
|
|
|
39
|
-
case "password":
|
|
40
|
-
value = await passwordPrompt(options);
|
|
41
|
-
break;
|
|
42
|
-
case "date":
|
|
43
|
-
value = await datePrompt({
|
|
44
|
-
...options,
|
|
45
|
-
dateFormat: "DD/MM/YYYY",
|
|
46
|
-
dateKind: "other"
|
|
47
|
-
});
|
|
48
|
-
break;
|
|
49
|
-
case "nextSteps":
|
|
50
|
-
await nextStepsPrompt(options);
|
|
51
|
-
value = null;
|
|
52
|
-
break;
|
|
53
|
-
case "end":
|
|
54
|
-
await endPrompt(options);
|
|
55
|
-
value = null;
|
|
56
|
-
break;
|
|
57
63
|
default:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
throw Error(`Unknown prompt type: ${type}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (action) {
|
|
68
|
+
await action();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
[id]: value,
|
|
73
|
+
};
|
|
64
74
|
}
|
|
@@ -1,37 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
text,
|
|
3
|
+
confirm,
|
|
4
|
+
select,
|
|
5
|
+
multiselect,
|
|
6
|
+
} from '../prompts/promptTwo.js';
|
|
7
|
+
|
|
8
|
+
const isString = (a) => typeof a === 'string';
|
|
9
|
+
|
|
2
10
|
export async function prompt(message, opts = {}) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
+
if (!opts.type || opts.type === 'text') {
|
|
12
|
+
return await text({
|
|
13
|
+
message,
|
|
14
|
+
defaultValue: opts.default,
|
|
15
|
+
placeholder: opts.placeholder,
|
|
16
|
+
initialValue: opts.initial,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (opts.type === 'confirm') {
|
|
21
|
+
return await confirm({
|
|
22
|
+
message,
|
|
23
|
+
initialValue: opts.initial,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (opts.type === 'select') {
|
|
28
|
+
return await select({
|
|
29
|
+
message,
|
|
30
|
+
options: opts.options.map((o) => isString(o) ? {
|
|
31
|
+
value: o,
|
|
32
|
+
label: o,
|
|
33
|
+
} : o),
|
|
34
|
+
initialValue: opts.initial,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (opts.type === 'multiselect') {
|
|
39
|
+
return await multiselect({
|
|
40
|
+
message,
|
|
41
|
+
options: opts.options.map((o) => isString(o) ? {
|
|
42
|
+
value: o,
|
|
43
|
+
label: o,
|
|
44
|
+
} : o),
|
|
45
|
+
required: opts.required,
|
|
46
|
+
initialValues: opts.initial,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw Error(`Unknown prompt type: ${opts.type}`);
|
|
37
51
|
}
|
|
@@ -1,58 +1,74 @@
|
|
|
1
|
-
import Prompt from
|
|
1
|
+
import Prompt from '../prompts/prompt.js';
|
|
2
|
+
|
|
2
3
|
export default class GroupMultiSelectPrompt 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
|
-
|
|
27
|
-
|
|
4
|
+
options;
|
|
5
|
+
cursor = 0;
|
|
6
|
+
getGroupItems(group) {
|
|
7
|
+
return this.options.filter((o) => o.group === group);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
isGroupSelected(group) {
|
|
11
|
+
const items = this.getGroupItems(group);
|
|
12
|
+
return items.every((i) => this.value.includes(i.value));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
toggleValue() {
|
|
16
|
+
const item = this.options[this.cursor];
|
|
17
|
+
|
|
18
|
+
if (item.group) {
|
|
19
|
+
const group = item.value;
|
|
20
|
+
const groupedItems = this.getGroupItems(group);
|
|
21
|
+
|
|
22
|
+
if (this.isGroupSelected(group)) {
|
|
23
|
+
this.value = this.value.filter((v) => groupedItems.findIndex((i) => i.value === v) === -1);
|
|
24
|
+
} else {
|
|
25
|
+
this.value = [
|
|
26
|
+
...this.value,
|
|
27
|
+
...groupedItems.map((i) => i.value),
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.value = Array.from(new Set(this.value));
|
|
32
|
+
} else {
|
|
33
|
+
const selected = this.value.includes(item.value);
|
|
34
|
+
this.value = selected ? this.value.filter((v) => v !== item.value) : [
|
|
35
|
+
...this.value,
|
|
36
|
+
item.value,
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
constructor(opts) {
|
|
42
|
+
super(opts, false);
|
|
43
|
+
const {options} = opts;
|
|
44
|
+
|
|
45
|
+
this.options = Object
|
|
46
|
+
.entries(options)
|
|
47
|
+
.flatMap(([key, option]) => [{
|
|
48
|
+
value: key,
|
|
49
|
+
group: true,
|
|
50
|
+
label: key,
|
|
51
|
+
},
|
|
52
|
+
...option.map((opt) => ({ ...opt,
|
|
53
|
+
group: key}))]);
|
|
54
|
+
this.value = opts.initialValues ?? [].slice();
|
|
55
|
+
this.cursor = Math.max(this.options.findIndex(({value}) => value === opts.cursorAt), 0);
|
|
56
|
+
this.on('cursor', (key) => {
|
|
57
|
+
switch(key) {
|
|
58
|
+
case 'left':
|
|
59
|
+
case 'up':
|
|
60
|
+
this.cursor = !this.cursor ? this.options.length - 1 : this.cursor - 1;
|
|
61
|
+
break;
|
|
62
|
+
|
|
63
|
+
case 'down':
|
|
64
|
+
case 'right':
|
|
65
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case 'space':
|
|
69
|
+
this.toggleValue();
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
28
73
|
}
|
|
29
|
-
}
|
|
30
|
-
constructor(opts) {
|
|
31
|
-
super(opts, false);
|
|
32
|
-
const { options } = opts;
|
|
33
|
-
this.options = Object.entries(options).flatMap(([key, option]) => [
|
|
34
|
-
{ value: key, group: true, label: key },
|
|
35
|
-
...option.map((opt) => ({ ...opt, group: key }))
|
|
36
|
-
]);
|
|
37
|
-
this.value = [...opts.initialValues ?? []];
|
|
38
|
-
this.cursor = Math.max(
|
|
39
|
-
this.options.findIndex(({ value }) => value === opts.cursorAt),
|
|
40
|
-
0
|
|
41
|
-
);
|
|
42
|
-
this.on("cursor", (key) => {
|
|
43
|
-
switch (key) {
|
|
44
|
-
case "left":
|
|
45
|
-
case "up":
|
|
46
|
-
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
47
|
-
break;
|
|
48
|
-
case "down":
|
|
49
|
-
case "right":
|
|
50
|
-
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
51
|
-
break;
|
|
52
|
-
case "space":
|
|
53
|
-
this.toggleValue();
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
74
|
}
|