@reliverse/relinka 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-npm/components/anykey/index.js +57 -77
- package/dist-npm/components/block/block.js +48 -61
- package/dist-npm/components/checkbox/index.js +178 -211
- package/dist-npm/components/confirm/confirm-main.js +85 -122
- package/dist-npm/components/confirm/confirm-three.js +24 -27
- package/dist-npm/components/confirm/index.js +36 -45
- package/dist-npm/components/core/Separator.js +15 -17
- package/dist-npm/components/core/create-prompt.js +101 -124
- package/dist-npm/components/core/errors.js +19 -15
- package/dist-npm/components/core/hook-engine.js +91 -120
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +16 -6
- package/dist-npm/components/core/lines.js +45 -54
- package/dist-npm/components/core/make-theme.js +21 -30
- package/dist-npm/components/core/position.js +27 -23
- package/dist-npm/components/core/promise-polyfill.js +11 -14
- package/dist-npm/components/core/screen-manager.js +59 -74
- package/dist-npm/components/core/theme.js +22 -32
- package/dist-npm/components/core/use-effect.js +9 -15
- package/dist-npm/components/core/use-keypress.js +19 -23
- package/dist-npm/components/core/use-memo.js +10 -16
- package/dist-npm/components/core/use-pagination.js +33 -32
- package/dist-npm/components/core/use-prefix.js +40 -38
- package/dist-npm/components/core/use-ref.js +2 -5
- package/dist-npm/components/core/use-state.js +15 -23
- package/dist-npm/components/core/useKeyPress.js +14 -17
- package/dist-npm/components/core/usePromptState.js +8 -14
- package/dist-npm/components/core/utils.js +7 -16
- package/dist-npm/components/date/date.js +173 -204
- package/dist-npm/components/editor/index.js +71 -92
- package/dist-npm/components/expand/index.js +96 -124
- package/dist-npm/components/figures/index.js +283 -294
- package/dist-npm/components/input/index.js +61 -87
- package/dist-npm/components/input/text-main.js +97 -124
- package/dist-npm/components/input/text.js +24 -28
- package/dist-npm/components/instance/basic.js +17 -25
- package/dist-npm/components/instance/browser.js +14 -18
- package/dist-npm/components/instance/reporter/basic.js +46 -65
- package/dist-npm/components/instance/reporter/browser.js +44 -47
- package/dist-npm/components/instance/reporter/fancy.js +83 -96
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +52 -62
- package/dist-npm/components/mono/monoTwo.js +35 -49
- package/dist-npm/components/multiselect/group-multiselect.js +55 -71
- package/dist-npm/components/multiselect/multi-select-two.js +97 -130
- package/dist-npm/components/multiselect/multi-select.js +43 -49
- package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
- package/dist-npm/components/multiselect/multiselect-main.js +158 -145
- package/dist-npm/components/multiselect/num-multi-select.js +97 -130
- package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
- package/dist-npm/components/next-steps/next-steps.js +23 -25
- package/dist-npm/components/number/index.js +78 -112
- package/dist-npm/components/number/number-main.js +95 -2
- package/dist-npm/components/password/index.js +54 -73
- package/dist-npm/components/password/password-main.js +119 -2
- package/dist-npm/components/password/password-three.js +26 -30
- package/dist-npm/components/progressbar/ProgressBar.js +45 -64
- package/dist-npm/components/progressbar/helper.js +33 -40
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +29 -44
- package/dist-npm/components/prompts/index.d.ts +1 -0
- package/dist-npm/components/prompts/index.js +46 -45
- package/dist-npm/components/prompts/prompt.js +211 -260
- package/dist-npm/components/prompts/promptTwo.js +561 -605
- package/dist-npm/components/prompts/relinka.js +237 -295
- package/dist-npm/components/range/range.js +247 -294
- package/dist-npm/components/rawlist/index.js +87 -107
- package/dist-npm/components/results/results.js +31 -37
- package/dist-npm/components/search/index.js +148 -193
- package/dist-npm/components/select/index.js +148 -186
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +124 -5
- package/dist-npm/components/select/select-key.js +24 -25
- package/dist-npm/components/select/select-main.d.ts +1 -0
- package/dist-npm/components/select/select-main.js +143 -133
- package/dist-npm/components/select/select-three.js +32 -36
- package/dist-npm/components/select/select-two.js +94 -87
- package/dist-npm/components/spinner/index.js +107 -136
- package/dist-npm/components/st-end/end.js +34 -26
- package/dist-npm/components/st-end/start.js +29 -15
- package/dist-npm/components/toggle/index.js +113 -137
- package/dist-npm/components/visual/animate/animate.js +53 -10
- package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
- package/dist-npm/main.js +1 -0
- package/dist-npm/testing/index.js +58 -83
- package/dist-npm/types/general.d.ts +1 -1
- package/dist-npm/types/general.js +0 -1
- package/dist-npm/types/index.js +2 -3
- package/dist-npm/types/keypress.js +35 -36
- package/dist-npm/types/readline.js +0 -1
- package/dist-npm/types/relinka.js +0 -1
- package/dist-npm/types/utils.js +0 -1
- package/dist-npm/utils/box.js +135 -137
- package/dist-npm/utils/color.js +65 -74
- package/dist-npm/utils/colorize.js +124 -156
- package/dist-npm/utils/component.js +532 -657
- package/dist-npm/utils/constants.js +64 -63
- package/dist-npm/utils/core.js +2 -3
- package/dist-npm/utils/decoder.js +244 -223
- package/dist-npm/utils/error.js +4 -9
- package/dist-npm/utils/errors.js +14 -4
- package/dist-npm/utils/format.js +19 -24
- package/dist-npm/utils/keypress.js +316 -414
- package/dist-npm/utils/log.js +11 -15
- package/dist-npm/utils/mapping.js +45 -52
- package/dist-npm/utils/messages.js +196 -183
- package/dist-npm/utils/platforms.js +16 -20
- package/dist-npm/utils/prompt-tmp.js +235 -286
- package/dist-npm/utils/prompt-two.js +235 -286
- package/dist-npm/utils/readline.js +5 -7
- package/dist-npm/utils/skeleton.js +130 -170
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +44 -58
- package/dist-npm/utils/terminal.js +23 -34
- package/dist-npm/utils/tree.js +30 -41
- package/dist-npm/utils/types.js +0 -1
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +36 -44
- package/package.json +14 -14
- package/dist-npm/mod.js +0 -2
- /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
|
@@ -1,59 +1,56 @@
|
|
|
1
|
-
const isString = (a) => typeof a === 'string';
|
|
2
|
-
|
|
3
1
|
export class BrowserReporter {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
options;
|
|
3
|
+
defaultColor;
|
|
4
|
+
levelColorMap;
|
|
5
|
+
typeColorMap;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = { ...options };
|
|
8
|
+
this.defaultColor = "#7f8c8d";
|
|
9
|
+
this.levelColorMap = {
|
|
10
|
+
0: "#c0392b",
|
|
11
|
+
|
|
12
|
+
1: "#f39c12",
|
|
13
|
+
|
|
14
|
+
3: "#00BCD4"
|
|
15
|
+
|
|
16
|
+
};
|
|
17
|
+
this.typeColorMap = {
|
|
18
|
+
success: "#2ecc71"
|
|
19
|
+
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
_getLogFn(level) {
|
|
23
|
+
if (level < 1) {
|
|
24
|
+
return console.__error || console.error;
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
26
|
+
if (level === 1) {
|
|
27
|
+
return console.__warn || console.warn;
|
|
33
28
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
return console.__log || console.log;
|
|
30
|
+
}
|
|
31
|
+
log(logObj) {
|
|
32
|
+
const consoleLogFn = this._getLogFn(logObj.level);
|
|
33
|
+
const type = logObj.type === "log" ? "" : logObj.type;
|
|
34
|
+
const tag = logObj.tag || "";
|
|
35
|
+
const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
|
|
36
|
+
const style = `
|
|
42
37
|
background: ${color};
|
|
43
38
|
border-radius: 0.5em;
|
|
44
39
|
color: white;
|
|
45
40
|
font-weight: bold;
|
|
46
41
|
padding: 2px 0.5em;
|
|
47
42
|
`;
|
|
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
|
-
|
|
54
|
-
consoleLogFn(`${badge}%c ${logObj.args[0]}`, style, '', ...logObj.args.slice(1));
|
|
55
|
-
} else {
|
|
56
|
-
consoleLogFn(badge, style, ...logObj.args);
|
|
57
|
-
}
|
|
49
|
+
"",
|
|
50
|
+
...logObj.args.slice(1)
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
consoleLogFn(badge, style, ...logObj.args);
|
|
58
54
|
}
|
|
55
|
+
}
|
|
59
56
|
}
|
|
@@ -1,114 +1,101 @@
|
|
|
1
|
-
import isUnicodeSupported from
|
|
2
|
-
import _stringWidth from
|
|
3
|
-
import {box} from
|
|
4
|
-
import {colors} from
|
|
5
|
-
import {parseStack} from
|
|
6
|
-
import {stripAnsi} from
|
|
7
|
-
import {BasicReporter} from
|
|
8
|
-
|
|
9
|
-
const isString = (a) => typeof a === 'string';
|
|
10
|
-
|
|
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";
|
|
11
8
|
export const TYPE_COLOR_MAP = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
info: "cyan",
|
|
10
|
+
fail: "red",
|
|
11
|
+
success: "green",
|
|
12
|
+
ready: "green",
|
|
13
|
+
start: "magenta"
|
|
17
14
|
};
|
|
18
15
|
export const LEVEL_COLOR_MAP = {
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
0: "red",
|
|
17
|
+
1: "yellow"
|
|
21
18
|
};
|
|
22
19
|
const unicode = isUnicodeSupported();
|
|
23
20
|
const s = (c, fallback) => unicode ? c : fallback;
|
|
24
|
-
|
|
25
21
|
const TYPE_ICONS = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
error: s("\u2716", "\xD7"),
|
|
23
|
+
fatal: s("\u2716", "\xD7"),
|
|
24
|
+
ready: s("\u2714", "\u221A"),
|
|
25
|
+
warn: s("\u26A0", "\u203C"),
|
|
26
|
+
info: s("\u2139", "i"),
|
|
27
|
+
success: s("\u2714", "\u221A"),
|
|
28
|
+
debug: s("\u2699", "D"),
|
|
29
|
+
trace: s("\u2192", "\u2192"),
|
|
30
|
+
fail: s("\u2716", "\xD7"),
|
|
31
|
+
start: s("\u25D0", "o"),
|
|
32
|
+
log: ""
|
|
37
33
|
};
|
|
38
|
-
|
|
39
34
|
function stringWidth(str) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return _stringWidth(str);
|
|
35
|
+
if (!Intl.Segmenter) {
|
|
36
|
+
return stripAnsi(str).length;
|
|
37
|
+
}
|
|
38
|
+
return _stringWidth(str);
|
|
45
39
|
}
|
|
46
|
-
|
|
47
40
|
export class FancyReporter extends BasicReporter {
|
|
48
|
-
|
|
49
|
-
formatStack(stack) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
// @ts-expect-error TODO: fix ts
|
|
42
|
+
formatStack(stack) {
|
|
43
|
+
return "\n" + parseStack(stack).map(
|
|
44
|
+
(line) => " " + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)
|
|
45
|
+
).join("\n");
|
|
46
|
+
}
|
|
47
|
+
formatType(logObj, isBadge, opts) {
|
|
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
|
+
);
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
55
|
+
return _type ? getColor(typeColor)(_type) : "";
|
|
56
|
+
}
|
|
57
|
+
// @ts-expect-error TODO: fix ts
|
|
58
|
+
formatLogObj(logObj, opts) {
|
|
59
|
+
const [message, ...additional] = this.formatArgs(logObj.args, opts).split(
|
|
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
|
|
62
70
|
}
|
|
63
|
-
|
|
64
|
-
const _type = isString(TYPE_ICONS[logObj.type]) ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
65
|
-
|
|
66
|
-
return _type ? getColor(typeColor)(_type) : '';
|
|
71
|
+
);
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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;
|
|
73
|
+
const date = this.formatDate(logObj.date, opts);
|
|
74
|
+
const coloredDate = date && colors.gray(date);
|
|
75
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
76
|
+
const type = this.formatType(logObj, isBadge, opts);
|
|
77
|
+
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
78
|
+
let line;
|
|
79
|
+
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
80
|
+
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
81
|
+
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
82
|
+
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
83
|
+
line += characterFormat(
|
|
84
|
+
additional.length > 0 ? "\n" + additional.join("\n") : ""
|
|
85
|
+
);
|
|
86
|
+
if (logObj.type === "trace") {
|
|
87
|
+
const _err = new Error("Trace: " + logObj.message);
|
|
88
|
+
line += this.formatStack(_err.stack || "");
|
|
101
89
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
90
|
+
return isBadge ? "\n" + line + "\n" : line;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function characterFormat(str) {
|
|
94
|
+
return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return colors[color] || colors.white;
|
|
96
|
+
function getColor(color = "white") {
|
|
97
|
+
return colors[color] || colors.white;
|
|
110
98
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
99
|
+
function getBgColor(color = "bgWhite") {
|
|
100
|
+
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
114
101
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {LogLevels, LogTypes} from
|
|
2
|
-
export {Relinka} from
|
|
1
|
+
export { LogLevels, LogTypes } from "../../utils/constants.js";
|
|
2
|
+
export { Relinka } from "../../components/prompts/relinka.js";
|
|
@@ -1,74 +1,64 @@
|
|
|
1
|
-
import {confirmPrompt} from
|
|
2
|
-
import {datePrompt} from
|
|
3
|
-
import {textPrompt} from
|
|
4
|
-
import {nextStepsPrompt} from
|
|
5
|
-
import {numberPrompt} from
|
|
6
|
-
import {passwordPrompt} from
|
|
7
|
-
import {numSelectPrompt} from
|
|
8
|
-
import {endPrompt} from
|
|
9
|
-
import {startPrompt} from
|
|
10
|
-
|
|
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";
|
|
11
10
|
export async function prompt(options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const { type, id, action } = options;
|
|
12
|
+
let value;
|
|
13
|
+
switch (type) {
|
|
14
|
+
case "start":
|
|
15
|
+
await startPrompt(options);
|
|
16
|
+
value = null;
|
|
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;
|
|
18
30
|
|
|
19
|
-
switch(type) {
|
|
20
|
-
case 'start':
|
|
21
|
-
await startPrompt(options);
|
|
22
|
-
value = null;
|
|
23
|
-
break;
|
|
24
31
|
|
|
25
|
-
case 'text':
|
|
26
|
-
value = await textPrompt(options);
|
|
27
|
-
break;
|
|
28
32
|
|
|
29
|
-
case 'number':
|
|
30
|
-
value = await numberPrompt(options);
|
|
31
|
-
break;
|
|
32
33
|
|
|
33
|
-
case 'confirm':
|
|
34
|
-
value = await confirmPrompt(options);
|
|
35
|
-
break;
|
|
36
34
|
|
|
37
|
-
case 'numSelect':
|
|
38
|
-
value = await numSelectPrompt(options);
|
|
39
|
-
break;
|
|
40
35
|
|
|
41
|
-
case 'password':
|
|
42
|
-
value = await passwordPrompt(options);
|
|
43
|
-
break;
|
|
44
36
|
|
|
45
|
-
case 'date':
|
|
46
|
-
value = await datePrompt({
|
|
47
|
-
...options,
|
|
48
|
-
dateFormat: 'DD/MM/YYYY',
|
|
49
|
-
dateKind: 'other',
|
|
50
|
-
});
|
|
51
|
-
break;
|
|
52
37
|
|
|
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;
|
|
62
38
|
|
|
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;
|
|
63
57
|
default:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
[id]: value,
|
|
73
|
-
};
|
|
58
|
+
throw new Error(`Unknown prompt type: ${type}`);
|
|
59
|
+
}
|
|
60
|
+
if (action) {
|
|
61
|
+
await action();
|
|
62
|
+
}
|
|
63
|
+
return { [id]: value };
|
|
74
64
|
}
|
|
@@ -1,51 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
text,
|
|
3
|
-
confirm,
|
|
4
|
-
select,
|
|
5
|
-
multiselect,
|
|
6
|
-
} from '../prompts/promptTwo.js';
|
|
7
|
-
|
|
8
|
-
const isString = (a) => typeof a === 'string';
|
|
9
|
-
|
|
1
|
+
import { text, confirm, select, multiselect } from "../prompts/promptTwo.js";
|
|
10
2
|
export async function prompt(message, opts = {}) {
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
required: opts.required,
|
|
46
|
-
initialValues: opts.initial,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
throw Error(`Unknown prompt type: ${opts.type}`);
|
|
3
|
+
if (!opts.type || opts.type === "text") {
|
|
4
|
+
return await text({
|
|
5
|
+
message,
|
|
6
|
+
defaultValue: opts.default,
|
|
7
|
+
placeholder: opts.placeholder,
|
|
8
|
+
initialValue: opts.initial
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (opts.type === "confirm") {
|
|
12
|
+
return await confirm({
|
|
13
|
+
message,
|
|
14
|
+
initialValue: opts.initial
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (opts.type === "select") {
|
|
18
|
+
return await select({
|
|
19
|
+
message,
|
|
20
|
+
options: opts.options.map(
|
|
21
|
+
(o) => typeof o === "string" ? { value: o, label: o } : o
|
|
22
|
+
),
|
|
23
|
+
initialValue: opts.initial
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (opts.type === "multiselect") {
|
|
27
|
+
return await multiselect({
|
|
28
|
+
message,
|
|
29
|
+
options: opts.options.map(
|
|
30
|
+
(o) => typeof o === "string" ? { value: o, label: o } : o
|
|
31
|
+
),
|
|
32
|
+
required: opts.required,
|
|
33
|
+
initialValues: opts.initial
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`Unknown prompt type: ${opts.type}`);
|
|
51
37
|
}
|
|
@@ -1,74 +1,58 @@
|
|
|
1
|
-
import Prompt from
|
|
2
|
-
|
|
1
|
+
import Prompt from "../prompts/prompt.js";
|
|
3
2
|
export default class GroupMultiSelectPrompt extends Prompt {
|
|
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
|
-
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
|
-
});
|
|
3
|
+
options;
|
|
4
|
+
cursor = 0;
|
|
5
|
+
getGroupItems(group) {
|
|
6
|
+
return this.options.filter((o) => o.group === group);
|
|
7
|
+
}
|
|
8
|
+
isGroupSelected(group) {
|
|
9
|
+
const items = this.getGroupItems(group);
|
|
10
|
+
return items.every((i) => this.value.includes(i.value));
|
|
11
|
+
}
|
|
12
|
+
toggleValue() {
|
|
13
|
+
const item = this.options[this.cursor];
|
|
14
|
+
if (item.group === true) {
|
|
15
|
+
const group = item.value;
|
|
16
|
+
const groupedItems = this.getGroupItems(group);
|
|
17
|
+
if (this.isGroupSelected(group)) {
|
|
18
|
+
this.value = this.value.filter(
|
|
19
|
+
(v) => groupedItems.findIndex((i) => i.value === v) === -1
|
|
20
|
+
);
|
|
21
|
+
} else {
|
|
22
|
+
this.value = [...this.value, ...groupedItems.map((i) => i.value)];
|
|
23
|
+
}
|
|
24
|
+
this.value = Array.from(new Set(this.value));
|
|
25
|
+
} else {
|
|
26
|
+
const selected = this.value.includes(item.value);
|
|
27
|
+
this.value = selected ? this.value.filter((v) => v !== item.value) : [...this.value, item.value];
|
|
73
28
|
}
|
|
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
|
+
}
|
|
74
58
|
}
|