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