@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,61 +1,81 @@
|
|
|
1
|
-
import logUpdate from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import logUpdate from 'log-update';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import {fmt} from '../../utils/messages.js';
|
|
4
|
+
import {restoreCursor} from '../../utils/terminal.js';
|
|
5
|
+
|
|
6
|
+
const isNumber = (a) => typeof a === 'number';
|
|
7
|
+
const isFn = (a) => typeof a === 'function';
|
|
8
|
+
const DEFAULT_MESSAGE = 'Press any key to continue...';
|
|
5
9
|
const CTRL_C_CODE = 3;
|
|
10
|
+
|
|
6
11
|
export async function anykeyPrompt(message = DEFAULT_MESSAGE, options = {}) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
process.stdin.pause();
|
|
26
|
-
restoreCursor();
|
|
27
|
-
};
|
|
28
|
-
const handleCtrlC = () => {
|
|
29
|
-
cleanup();
|
|
30
|
-
if (ctrlC === "reject") {
|
|
31
|
-
reject(new Error("User pressed CTRL+C"));
|
|
32
|
-
} else if (ctrlC === false) {
|
|
33
|
-
resolve();
|
|
34
|
-
} else if (typeof ctrlC === "number") {
|
|
35
|
-
process.exit(ctrlC);
|
|
36
|
-
} else {
|
|
37
|
-
throw new TypeError("Invalid ctrlC option");
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const handler = (buffer) => {
|
|
41
|
-
cleanup();
|
|
42
|
-
if (message && !preserveLog) {
|
|
43
|
-
logUpdate.clear();
|
|
44
|
-
} else {
|
|
45
|
-
logUpdate.done();
|
|
46
|
-
process.stdout.write("\n");
|
|
47
|
-
}
|
|
48
|
-
const [firstByte] = buffer;
|
|
49
|
-
if (firstByte === CTRL_C_CODE) {
|
|
50
|
-
handleCtrlC();
|
|
51
|
-
} else {
|
|
52
|
-
resolve();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
process.stdin.resume();
|
|
56
|
-
if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
|
|
57
|
-
process.stdin.setRawMode(true);
|
|
12
|
+
const {
|
|
13
|
+
ctrlC = 1,
|
|
14
|
+
preserveLog = false,
|
|
15
|
+
hideMessage = false,
|
|
16
|
+
} = options;
|
|
17
|
+
|
|
18
|
+
if (message) {
|
|
19
|
+
message = fmt({
|
|
20
|
+
type: 'M_GENERAL',
|
|
21
|
+
title: message,
|
|
22
|
+
titleColor: 'dim',
|
|
23
|
+
dontRemoveBar: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (message && !hideMessage) {
|
|
28
|
+
logUpdate(message);
|
|
58
29
|
}
|
|
59
|
-
|
|
60
|
-
|
|
30
|
+
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const cleanup = () => {
|
|
33
|
+
process.stdin.removeListener('data', handler);
|
|
34
|
+
if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
|
|
35
|
+
process.stdin.setRawMode(false);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
process.stdin.pause();
|
|
39
|
+
restoreCursor();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleCtrlC = () => {
|
|
43
|
+
cleanup();
|
|
44
|
+
if (ctrlC === 'reject') {
|
|
45
|
+
reject(Error('User pressed CTRL+C'));
|
|
46
|
+
} else if (!ctrlC) {
|
|
47
|
+
resolve();
|
|
48
|
+
} else if (isNumber(ctrlC)) {
|
|
49
|
+
process.exit(ctrlC);
|
|
50
|
+
} else {
|
|
51
|
+
throw TypeError('Invalid ctrlC option');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handler = (buffer) => {
|
|
57
|
+
cleanup();
|
|
58
|
+
if (message && !preserveLog) {
|
|
59
|
+
logUpdate.clear();
|
|
60
|
+
} else {
|
|
61
|
+
logUpdate.done();
|
|
62
|
+
process.stdout.write('\n');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const [firstByte] = buffer;
|
|
66
|
+
|
|
67
|
+
if (firstByte === CTRL_C_CODE) {
|
|
68
|
+
handleCtrlC();
|
|
69
|
+
} else {
|
|
70
|
+
resolve();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
process.stdin.resume();
|
|
75
|
+
if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
|
|
76
|
+
process.stdin.setRawMode(true);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
process.stdin.once('data', handler);
|
|
80
|
+
});
|
|
61
81
|
}
|
|
@@ -1,52 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as readline from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
input.setRawMode(true);
|
|
20
|
-
}
|
|
21
|
-
const clear = (data, { name }) => {
|
|
22
|
-
const str = String(data);
|
|
23
|
-
if (str === "") {
|
|
24
|
-
process.exit(0);
|
|
25
|
-
}
|
|
26
|
-
if (!overwrite) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const dx = name === "return" ? 0 : -1;
|
|
30
|
-
const dy = name === "return" ? -1 : 0;
|
|
31
|
-
readline.moveCursor(output, dx, dy, () => {
|
|
32
|
-
readline.clearLine(output, 1, () => {
|
|
33
|
-
input.once("keypress", clear);
|
|
34
|
-
});
|
|
1
|
+
import process, {stdin, stdout} from 'node:process';
|
|
2
|
+
import * as readline from 'node:readline';
|
|
3
|
+
import {removeCursor, restoreCursor} from '../../utils/terminal.js';
|
|
4
|
+
|
|
5
|
+
const isWindows = globalThis.process.platform.startsWith('win');
|
|
6
|
+
|
|
7
|
+
export default function block(overrides = {}) {
|
|
8
|
+
const {
|
|
9
|
+
input = stdin,
|
|
10
|
+
output = stdout,
|
|
11
|
+
overwrite = true,
|
|
12
|
+
hideCursor = true,
|
|
13
|
+
} = overrides;
|
|
14
|
+
const rl = readline.createInterface({
|
|
15
|
+
input,
|
|
16
|
+
output,
|
|
17
|
+
prompt: '',
|
|
18
|
+
tabSize: 1,
|
|
35
19
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
input.once("keypress", clear);
|
|
41
|
-
return () => {
|
|
42
|
-
input.off("keypress", clear);
|
|
43
|
-
if (hideCursor) {
|
|
44
|
-
restoreCursor();
|
|
20
|
+
|
|
21
|
+
readline.emitKeypressEvents(input, rl);
|
|
22
|
+
if (input.isTTY) {
|
|
23
|
+
input.setRawMode(true);
|
|
45
24
|
}
|
|
46
|
-
|
|
47
|
-
|
|
25
|
+
|
|
26
|
+
const clear = (data, {name}) => {
|
|
27
|
+
const str = String(data);
|
|
28
|
+
|
|
29
|
+
if (str === '') {
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!overwrite) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const dx = name === 'return' ? 0 : -1;
|
|
38
|
+
const dy = name === 'return' ? -1 : 0;
|
|
39
|
+
|
|
40
|
+
readline.moveCursor(output, dx, dy, () => {
|
|
41
|
+
readline.clearLine(output, 1, () => {
|
|
42
|
+
input.once('keypress', clear);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (hideCursor) {
|
|
48
|
+
removeCursor();
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
|
|
51
|
+
input.once('keypress', clear);
|
|
52
|
+
return () => {
|
|
53
|
+
input.off('keypress', clear);
|
|
54
|
+
if (hideCursor) {
|
|
55
|
+
restoreCursor();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (input.isTTY && !isWindows) {
|
|
59
|
+
input.setRawMode(false);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
rl.terminal = false;
|
|
63
|
+
rl.close();
|
|
64
|
+
};
|
|
52
65
|
}
|