@reliverse/relinka 1.1.5 → 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 -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,67 +1,82 @@
|
|
|
1
|
-
import ansiEscapes from
|
|
2
|
-
import stripAnsi from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const
|
|
1
|
+
import ansiEscapes from 'ansi-escapes';
|
|
2
|
+
import stripAnsi from 'strip-ansi';
|
|
3
|
+
import {breakLines, readlineWidth} from './utils.js';
|
|
4
|
+
|
|
5
|
+
const height = (content) => content.split('\n').length;
|
|
6
|
+
const lastLine = (content) => content
|
|
7
|
+
.split('\n')
|
|
8
|
+
.pop() ?? '';
|
|
9
|
+
|
|
6
10
|
function cursorDown(n) {
|
|
7
|
-
|
|
11
|
+
return n > 0 ? ansiEscapes.cursorDown(n) : '';
|
|
8
12
|
}
|
|
13
|
+
|
|
9
14
|
export default class ScreenManager {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
// These variables are keeping information to allow correct prompt re-rendering
|
|
16
|
-
height = 0;
|
|
17
|
-
extraLinesUnderPrompt = 0;
|
|
18
|
-
cursorPos;
|
|
19
|
-
write(content) {
|
|
20
|
-
this.rl.output.unmute();
|
|
21
|
-
this.rl.output.write(content);
|
|
22
|
-
this.rl.output.mute();
|
|
23
|
-
}
|
|
24
|
-
render(content, bottomContent = "") {
|
|
25
|
-
const promptLine = lastLine(content);
|
|
26
|
-
const rawPromptLine = stripAnsi(promptLine);
|
|
27
|
-
let prompt = rawPromptLine;
|
|
28
|
-
if (this.rl.line.length > 0) {
|
|
29
|
-
prompt = prompt.slice(0, -this.rl.line.length);
|
|
15
|
+
constructor(rl) {
|
|
16
|
+
this.rl = rl;
|
|
17
|
+
this.rl = rl;
|
|
18
|
+
this.cursorPos = rl.getCursorPos();
|
|
30
19
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
// These variables are keeping information to allow correct prompt re-rendering
|
|
21
|
+
height = 0;
|
|
22
|
+
extraLinesUnderPrompt = 0;
|
|
23
|
+
cursorPos;
|
|
24
|
+
write(content) {
|
|
25
|
+
this.rl.output.unmute();
|
|
26
|
+
this.rl.output.write(content);
|
|
27
|
+
this.rl.output.mute();
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
|
|
30
|
+
render(content, bottomContent = '') {
|
|
31
|
+
const promptLine = lastLine(content);
|
|
32
|
+
const rawPromptLine = stripAnsi(promptLine);
|
|
33
|
+
let prompt = rawPromptLine;
|
|
34
|
+
|
|
35
|
+
if (this.rl.line.length > 0) {
|
|
36
|
+
prompt = prompt.slice(0, -this.rl.line.length);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.rl.setPrompt(prompt);
|
|
40
|
+
this.cursorPos = this.rl.getCursorPos();
|
|
41
|
+
const width = readlineWidth();
|
|
42
|
+
|
|
43
|
+
content = breakLines(content, width);
|
|
44
|
+
bottomContent = breakLines(bottomContent, width);
|
|
45
|
+
if (!(rawPromptLine.length % width)) {
|
|
46
|
+
content += '\n';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let output = content + (bottomContent ? `
|
|
50
|
+
${bottomContent}` : '');
|
|
51
|
+
const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
|
|
52
|
+
const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
|
|
53
|
+
|
|
54
|
+
if (bottomContentHeight > 0) {
|
|
55
|
+
output += ansiEscapes.cursorUp(bottomContentHeight);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
output += ansiEscapes.cursorTo(this.cursorPos.cols);
|
|
59
|
+
this.write(cursorDown(this.extraLinesUnderPrompt) + ansiEscapes.eraseLines(this.height) + output);
|
|
60
|
+
this.extraLinesUnderPrompt = bottomContentHeight;
|
|
61
|
+
this.height = height(output);
|
|
44
62
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
|
|
64
|
+
checkCursorPos() {
|
|
65
|
+
const cursorPos = this.rl.getCursorPos();
|
|
66
|
+
|
|
67
|
+
if (cursorPos.cols !== this.cursorPos.cols) {
|
|
68
|
+
this.write(ansiEscapes.cursorTo(cursorPos.cols));
|
|
69
|
+
this.cursorPos = cursorPos;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
done({clearContent}) {
|
|
74
|
+
this.rl.setPrompt('');
|
|
75
|
+
let output = cursorDown(this.extraLinesUnderPrompt);
|
|
76
|
+
|
|
77
|
+
output += clearContent ? ansiEscapes.eraseLines(this.height) : '\n';
|
|
78
|
+
output += ansiEscapes.cursorShow;
|
|
79
|
+
this.write(output);
|
|
80
|
+
this.rl.close();
|
|
57
81
|
}
|
|
58
|
-
}
|
|
59
|
-
done({ clearContent }) {
|
|
60
|
-
this.rl.setPrompt("");
|
|
61
|
-
let output = cursorDown(this.extraLinesUnderPrompt);
|
|
62
|
-
output += clearContent ? ansiEscapes.eraseLines(this.height) : "\n";
|
|
63
|
-
output += ansiEscapes.cursorShow;
|
|
64
|
-
this.write(output);
|
|
65
|
-
this.rl.close();
|
|
66
|
-
}
|
|
67
82
|
}
|
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
import colors from
|
|
2
|
-
import figures from
|
|
1
|
+
import colors from 'picocolors';
|
|
2
|
+
import figures from '../../components/figures/index.js';
|
|
3
|
+
|
|
3
4
|
export const defaultTheme = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
prefix: {
|
|
6
|
+
idle: colors.blue('?'),
|
|
7
|
+
|
|
8
|
+
done: colors.green(figures.tick),
|
|
9
|
+
},
|
|
10
|
+
spinner: {
|
|
11
|
+
interval: 80,
|
|
12
|
+
frames: [
|
|
13
|
+
'\u280B',
|
|
14
|
+
'\u2819',
|
|
15
|
+
'\u2839',
|
|
16
|
+
'\u2838',
|
|
17
|
+
'\u283C',
|
|
18
|
+
'\u2834',
|
|
19
|
+
'\u2826',
|
|
20
|
+
'\u2827',
|
|
21
|
+
'\u2807',
|
|
22
|
+
'\u280F',
|
|
23
|
+
].map((frame) => colors.yellow(frame)),
|
|
24
|
+
},
|
|
25
|
+
style: {
|
|
26
|
+
answer: colors.cyan,
|
|
27
|
+
message: colors.bold,
|
|
28
|
+
error: (text) => colors.red(`> ${text}`),
|
|
29
|
+
defaultAnswer: (text) => colors.dim(`(${text})`),
|
|
30
|
+
help: colors.dim,
|
|
31
|
+
highlight: colors.cyan,
|
|
32
|
+
key: (text) => colors.cyan(colors.bold(`<${text}>`)),
|
|
33
|
+
},
|
|
24
34
|
};
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
withPointer,
|
|
3
|
+
effectScheduler,
|
|
4
|
+
} from './hook-engine.js';
|
|
5
|
+
|
|
2
6
|
export function useEffect(cb, depArray) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
withPointer((pointer) => {
|
|
8
|
+
const oldDeps = pointer.get();
|
|
9
|
+
const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
|
|
10
|
+
|
|
11
|
+
if (hasChanged) {
|
|
12
|
+
effectScheduler.queue(cb);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
pointer.set(depArray);
|
|
16
|
+
});
|
|
11
17
|
}
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {withUpdates} from './hook-engine.js';
|
|
2
|
+
import {useEffect} from './use-effect.js';
|
|
3
|
+
import {useRef} from './use-ref.js';
|
|
4
|
+
|
|
4
5
|
export function useKeypress(userHandler) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
const signal = useRef(userHandler);
|
|
7
|
+
|
|
8
|
+
signal.current = userHandler;
|
|
9
|
+
useEffect((rl) => {
|
|
10
|
+
let ignore = false;
|
|
11
|
+
const handler = withUpdates((_input, event) => {
|
|
12
|
+
if (ignore) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void signal.current(event, rl);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
rl.input.on('keypress', handler);
|
|
20
|
+
return () => {
|
|
21
|
+
ignore = true;
|
|
22
|
+
rl.input.removeListener('keypress', handler);
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
21
25
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {withPointer} from './hook-engine.js';
|
|
2
|
+
|
|
2
3
|
export function useMemo(fn, dependencies) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
return withPointer((pointer) => {
|
|
5
|
+
const prev = pointer.get();
|
|
6
|
+
|
|
7
|
+
if (!prev || prev.dependencies.length !== dependencies.length || prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
|
|
8
|
+
const value = fn();
|
|
9
|
+
pointer.set({
|
|
10
|
+
value,
|
|
11
|
+
dependencies,
|
|
12
|
+
});
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return prev.value;
|
|
17
|
+
});
|
|
12
18
|
}
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
}).join("\n");
|
|
1
|
+
import {lines} from './lines.js';
|
|
2
|
+
import {finite, infinite} from './position.js';
|
|
3
|
+
import {useRef} from './use-ref.js';
|
|
4
|
+
import {readlineWidth} from './utils.js';
|
|
5
|
+
|
|
6
|
+
export function usePagination({items, active, renderItem, pageSize, loop = true}) {
|
|
7
|
+
const state = useRef({
|
|
8
|
+
position: 0,
|
|
9
|
+
lastActive: 0,
|
|
10
|
+
});
|
|
11
|
+
const position = loop ? infinite({
|
|
12
|
+
active,
|
|
13
|
+
lastActive: state.current.lastActive,
|
|
14
|
+
total: items.length,
|
|
15
|
+
pageSize,
|
|
16
|
+
pointer: state.current.position,
|
|
17
|
+
}) : finite({
|
|
18
|
+
active,
|
|
19
|
+
total: items.length,
|
|
20
|
+
pageSize,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
state.current.position = position;
|
|
24
|
+
state.current.lastActive = active;
|
|
25
|
+
return lines({
|
|
26
|
+
items,
|
|
27
|
+
width: readlineWidth(),
|
|
28
|
+
renderItem,
|
|
29
|
+
active,
|
|
30
|
+
position,
|
|
31
|
+
pageSize,
|
|
32
|
+
}).join('\n');
|
|
34
33
|
}
|
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
|
|
1
|
+
import {AsyncResource} from 'node:async_hooks';
|
|
2
|
+
import {makeTheme} from './make-theme.js';
|
|
3
|
+
import {useEffect} from './use-effect.js';
|
|
4
|
+
import {useState} from './use-state.js';
|
|
5
|
+
|
|
6
|
+
const isString = (a) => typeof a === 'string';
|
|
7
|
+
|
|
8
|
+
export function usePrefix({status = 'idle', theme}) {
|
|
9
|
+
const [showLoader, setShowLoader] = useState(false);
|
|
10
|
+
const [tick, setTick] = useState(0);
|
|
11
|
+
const {prefix, spinner} = makeTheme(theme);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (status === 'loading') {
|
|
15
|
+
let tickInterval;
|
|
16
|
+
let inc = -1;
|
|
17
|
+
const delayTimeout = setTimeout(AsyncResource.bind(() => {
|
|
18
|
+
setShowLoader(true);
|
|
19
|
+
tickInterval = setInterval(AsyncResource.bind(() => {
|
|
20
|
+
++inc;
|
|
21
|
+
setTick(inc % spinner.frames.length);
|
|
22
|
+
}), spinner.interval);
|
|
23
|
+
}), 300);
|
|
24
|
+
|
|
25
|
+
return () => {
|
|
26
|
+
clearTimeout(delayTimeout);
|
|
27
|
+
clearInterval(tickInterval);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setShowLoader(false);
|
|
32
|
+
}, [status]);
|
|
33
|
+
if (showLoader) {
|
|
34
|
+
return spinner.frames[tick];
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const iconName = status === "loading" ? "idle" : status;
|
|
41
|
-
return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix.idle;
|
|
36
|
+
|
|
37
|
+
const iconName = status === 'loading' ? 'idle' : status;
|
|
38
|
+
|
|
39
|
+
return isString(prefix) ? prefix : prefix[iconName] ?? prefix.idle;
|
|
42
40
|
}
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {withPointer, handleChange} from './hook-engine.js';
|
|
2
|
+
|
|
3
|
+
const isFn = (a) => typeof a === 'function';
|
|
4
|
+
|
|
2
5
|
export function useState(defaultValue) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
return withPointer((pointer) => {
|
|
7
|
+
const setFn = (newValue) => {
|
|
8
|
+
if (pointer.get() !== newValue) {
|
|
9
|
+
pointer.set(newValue);
|
|
10
|
+
handleChange();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
if (pointer.initialized) {
|
|
15
|
+
return [
|
|
16
|
+
pointer.get(),
|
|
17
|
+
setFn,
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const value = isFn(defaultValue) ? defaultValue() : defaultValue;
|
|
22
|
+
pointer.set(value);
|
|
23
|
+
return [value, setFn];
|
|
24
|
+
});
|
|
17
25
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import readline from
|
|
1
|
+
import {stdin} from 'node:process';
|
|
2
|
+
import readline from 'node:readline';
|
|
3
|
+
|
|
3
4
|
export function useKeyPress(callback) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
stdin.
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
readline.emitKeypressEvents(stdin);
|
|
6
|
+
if (stdin.isTTY) {
|
|
7
|
+
stdin.setRawMode(true);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const onKeypress = (str, key) => {
|
|
11
|
+
callback(str, key);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
stdin.on('keypress', onKeypress);
|
|
15
|
+
return () => {
|
|
16
|
+
stdin.setRawMode(false);
|
|
17
|
+
stdin.off('keypress', onKeypress);
|
|
18
|
+
};
|
|
16
19
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {useEffect} from '../../components/core/use-effect.js';
|
|
2
|
+
import {useState} from '../../components/core/use-state.js';
|
|
3
|
+
|
|
3
4
|
export function usePromptState(initialState) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const [state, setState] = useState(initialState);
|
|
6
|
+
const [figure, setFigure] = useState('\u{1F7E2}');
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
setFigure('\u{1F7E2}');
|
|
10
|
+
}, [state]);
|
|
11
|
+
return {
|
|
12
|
+
state,
|
|
13
|
+
setState,
|
|
14
|
+
figure,
|
|
15
|
+
};
|
|
10
16
|
}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import cliWidth from
|
|
2
|
-
import wrapAnsi from
|
|
3
|
-
import {
|
|
1
|
+
import cliWidth from 'cli-width';
|
|
2
|
+
import wrapAnsi from 'wrap-ansi';
|
|
3
|
+
import {readline} from './hook-engine.js';
|
|
4
|
+
|
|
4
5
|
export function breakLines(content, width) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
return content
|
|
7
|
+
.split('\n')
|
|
8
|
+
.flatMap((line) => wrapAnsi(line, width, {
|
|
9
|
+
trim: false,
|
|
10
|
+
hard: true,
|
|
11
|
+
}).split('\n').map((str) => str.trimEnd()))
|
|
12
|
+
.join('\n');
|
|
8
13
|
}
|
|
14
|
+
|
|
9
15
|
export function readlineWidth() {
|
|
10
|
-
|
|
16
|
+
return cliWidth({
|
|
17
|
+
defaultWidth: 80,
|
|
18
|
+
output: readline().output,
|
|
19
|
+
});
|
|
11
20
|
}
|