@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,124 +1,104 @@
|
|
|
1
|
-
import colors from
|
|
1
|
+
import colors from "picocolors";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from
|
|
12
|
-
|
|
13
|
-
const isString = (a) => typeof a === 'string';
|
|
14
|
-
|
|
3
|
+
createPrompt,
|
|
4
|
+
useMemo,
|
|
5
|
+
useState,
|
|
6
|
+
useKeypress,
|
|
7
|
+
usePrefix,
|
|
8
|
+
isEnterKey,
|
|
9
|
+
Separator,
|
|
10
|
+
makeTheme
|
|
11
|
+
} from "../../components/core/index.js";
|
|
15
12
|
const numberRegex = /\d+/;
|
|
16
|
-
|
|
17
13
|
function isSelectableChoice(choice) {
|
|
18
|
-
|
|
14
|
+
return choice != null && !Separator.isSeparator(choice);
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
function normalizeChoices(choices) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
key: choice.key ?? String(index),
|
|
48
|
-
};
|
|
49
|
-
});
|
|
17
|
+
let index = 0;
|
|
18
|
+
return choices.map((choice) => {
|
|
19
|
+
if (Separator.isSeparator(choice)) {
|
|
20
|
+
return choice;
|
|
21
|
+
}
|
|
22
|
+
index += 1;
|
|
23
|
+
if (typeof choice === "string") {
|
|
24
|
+
return {
|
|
25
|
+
value: choice,
|
|
26
|
+
name: choice,
|
|
27
|
+
short: choice,
|
|
28
|
+
key: String(index)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const name = choice.name ?? String(choice.value);
|
|
32
|
+
return {
|
|
33
|
+
|
|
34
|
+
value: choice.value,
|
|
35
|
+
name,
|
|
36
|
+
|
|
37
|
+
short: choice.short ?? name,
|
|
38
|
+
|
|
39
|
+
key: choice.key ?? String(index)
|
|
40
|
+
};
|
|
41
|
+
});
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const choices = useMemo(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
const rawlist = createPrompt(
|
|
44
|
+
(config, done) => {
|
|
45
|
+
const choices = useMemo(
|
|
46
|
+
() => normalizeChoices(config.choices),
|
|
47
|
+
[config.choices]
|
|
48
|
+
);
|
|
49
|
+
const [status, setStatus] = useState("idle");
|
|
50
|
+
const [value, setValue] = useState("");
|
|
57
51
|
const [errorMsg, setError] = useState();
|
|
58
52
|
const theme = makeTheme(config.theme);
|
|
59
|
-
const prefix = usePrefix({
|
|
60
|
-
status,
|
|
61
|
-
theme,
|
|
62
|
-
});
|
|
63
|
-
|
|
53
|
+
const prefix = usePrefix({ status, theme });
|
|
64
54
|
useKeypress((key, rl) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} else {
|
|
82
|
-
setError(`"${colors.red(value)}" isn't an available option`);
|
|
83
|
-
}
|
|
55
|
+
if (isEnterKey(key)) {
|
|
56
|
+
let selectedChoice;
|
|
57
|
+
if (numberRegex.test(value)) {
|
|
58
|
+
const answer = Number.parseInt(value, 10) - 1;
|
|
59
|
+
selectedChoice = choices.filter(isSelectableChoice)[answer];
|
|
60
|
+
} else {
|
|
61
|
+
selectedChoice = choices.find(
|
|
62
|
+
(choice) => isSelectableChoice(choice) && choice.key === value
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (isSelectableChoice(selectedChoice)) {
|
|
66
|
+
setValue(selectedChoice.short);
|
|
67
|
+
setStatus("done");
|
|
68
|
+
done(selectedChoice.value);
|
|
69
|
+
} else if (value === "") {
|
|
70
|
+
setError("Please input a value");
|
|
84
71
|
} else {
|
|
85
|
-
|
|
86
|
-
setError(void 0);
|
|
72
|
+
setError(`"${colors.red(value)}" isn't an available option`);
|
|
87
73
|
}
|
|
74
|
+
} else {
|
|
75
|
+
setValue(rl.line);
|
|
76
|
+
setError(void 0);
|
|
77
|
+
}
|
|
88
78
|
});
|
|
89
79
|
const message = theme.style.message(config.message, status);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return `${prefix} ${message} ${theme.style.answer(value)}`;
|
|
80
|
+
if (status === "done") {
|
|
81
|
+
return `${prefix} ${message} ${theme.style.answer(value)}`;
|
|
93
82
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return line;
|
|
108
|
-
})
|
|
109
|
-
.join('\n');
|
|
110
|
-
|
|
111
|
-
let error = '';
|
|
112
|
-
|
|
83
|
+
const choicesStr = choices.map((choice) => {
|
|
84
|
+
if (Separator.isSeparator(choice)) {
|
|
85
|
+
return ` ${choice.separator}`;
|
|
86
|
+
}
|
|
87
|
+
const line = ` ${choice.key}) ${choice.name}`;
|
|
88
|
+
if (choice.key === value.toLowerCase()) {
|
|
89
|
+
return theme.style.highlight(line);
|
|
90
|
+
}
|
|
91
|
+
return line;
|
|
92
|
+
}).join("\n");
|
|
93
|
+
let error = "";
|
|
113
94
|
if (errorMsg) {
|
|
114
|
-
|
|
95
|
+
error = theme.style.error(errorMsg);
|
|
115
96
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
97
|
+
return [
|
|
98
|
+
`${prefix} ${message} ${value}`,
|
|
99
|
+
[choicesStr, error].filter(Boolean).join("\n")
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
);
|
|
122
103
|
export default rawlist;
|
|
123
|
-
|
|
124
|
-
export {Separator} from '../../components/core/index.js';
|
|
104
|
+
export { Separator } from "../../components/core/index.js";
|
|
@@ -1,40 +1,34 @@
|
|
|
1
|
-
import {Type} from
|
|
2
|
-
import {Value} from
|
|
3
|
-
import {msg} from
|
|
4
|
-
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { Value } from "@sinclair/typebox/value";
|
|
3
|
+
import { msg } from "../../utils/messages.js";
|
|
5
4
|
const ResultsSchema = Type.Object({
|
|
6
|
-
|
|
5
|
+
username: Type.String()
|
|
7
6
|
});
|
|
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
|
-
content: formattedResults,
|
|
36
|
-
titleColor: 'cyan',
|
|
37
|
-
contentColor: 'dim',
|
|
38
|
-
});
|
|
39
|
-
}
|
|
7
|
+
export async function promptsDisplayResults({
|
|
8
|
+
results,
|
|
9
|
+
inline = true
|
|
10
|
+
}) {
|
|
11
|
+
if (!Value.Check(ResultsSchema, results)) {
|
|
12
|
+
throw new Error("Invalid results structure.");
|
|
13
|
+
}
|
|
14
|
+
const title = "Your input results:";
|
|
15
|
+
if (inline) {
|
|
16
|
+
const formattedResults = Object.entries(results).map(([key, value]) => `${key}: ${value}`).join(", ");
|
|
17
|
+
msg({
|
|
18
|
+
type: "M_INFO",
|
|
19
|
+
title,
|
|
20
|
+
content: formattedResults,
|
|
21
|
+
titleColor: "cyan",
|
|
22
|
+
contentColor: "dim"
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
const formattedResults = JSON.stringify(results, null, 2);
|
|
26
|
+
msg({
|
|
27
|
+
type: "M_INFO",
|
|
28
|
+
title,
|
|
29
|
+
content: formattedResults,
|
|
30
|
+
titleColor: "cyan",
|
|
31
|
+
contentColor: "dim"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
40
34
|
}
|
|
@@ -1,231 +1,186 @@
|
|
|
1
|
-
import colors from
|
|
1
|
+
import colors from "picocolors";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from
|
|
15
|
-
import figures from
|
|
16
|
-
|
|
17
|
-
const isString = (a) => typeof a === 'string';
|
|
18
|
-
|
|
3
|
+
createPrompt,
|
|
4
|
+
useState,
|
|
5
|
+
useKeypress,
|
|
6
|
+
usePrefix,
|
|
7
|
+
usePagination,
|
|
8
|
+
useRef,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
isEnterKey,
|
|
12
|
+
Separator,
|
|
13
|
+
makeTheme
|
|
14
|
+
} from "../../components/core/index.js";
|
|
15
|
+
import figures from "../../components/figures/index.js";
|
|
19
16
|
const searchTheme = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
helpMode: 'auto',
|
|
17
|
+
icon: { cursor: figures.pointer },
|
|
18
|
+
style: {
|
|
19
|
+
disabled: (text) => colors.dim(`- ${text}`),
|
|
20
|
+
searchTerm: (text) => colors.cyan(text),
|
|
21
|
+
description: (text) => colors.cyan(text)
|
|
22
|
+
},
|
|
23
|
+
helpMode: "auto"
|
|
29
24
|
};
|
|
30
|
-
|
|
31
25
|
function isSelectable(item) {
|
|
32
|
-
|
|
26
|
+
return !Separator.isSeparator(item) && !item.disabled;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
function normalizeChoices(choices) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
});
|
|
29
|
+
return choices.map((choice) => {
|
|
30
|
+
if (Separator.isSeparator(choice)) {
|
|
31
|
+
return choice;
|
|
32
|
+
}
|
|
33
|
+
if (typeof choice === "string") {
|
|
34
|
+
return {
|
|
35
|
+
value: choice,
|
|
36
|
+
name: choice,
|
|
37
|
+
short: choice,
|
|
38
|
+
disabled: false
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const name = choice.name ?? String(choice.value);
|
|
42
|
+
return {
|
|
43
|
+
|
|
44
|
+
value: choice.value,
|
|
45
|
+
name,
|
|
46
|
+
|
|
47
|
+
description: choice.description,
|
|
48
|
+
|
|
49
|
+
short: choice.short ?? name,
|
|
50
|
+
|
|
51
|
+
disabled: choice.disabled ?? false
|
|
52
|
+
};
|
|
53
|
+
});
|
|
63
54
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const {pageSize = 7, validate = () => true} = config;
|
|
55
|
+
const search = createPrompt(
|
|
56
|
+
(config, done) => {
|
|
57
|
+
const { pageSize = 7, validate = () => true } = config;
|
|
67
58
|
const theme = makeTheme(searchTheme, config.theme);
|
|
68
59
|
const firstRender = useRef(true);
|
|
69
|
-
const [status, setStatus] = useState(
|
|
70
|
-
const [searchTerm, setSearchTerm] = useState(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
const [status, setStatus] = useState("loading");
|
|
61
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
62
|
+
const [searchResults, setSearchResults] = useState(
|
|
63
|
+
[]
|
|
64
|
+
);
|
|
74
65
|
const [searchError, setSearchError] = useState();
|
|
75
|
-
const prefix = usePrefix({
|
|
76
|
-
status,
|
|
77
|
-
theme,
|
|
78
|
-
});
|
|
79
|
-
|
|
66
|
+
const prefix = usePrefix({ status, theme });
|
|
80
67
|
const bounds = useMemo(() => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
first,
|
|
86
|
-
last,
|
|
87
|
-
};
|
|
68
|
+
const first = searchResults.findIndex(isSelectable);
|
|
69
|
+
const last = searchResults.findLastIndex(isSelectable);
|
|
70
|
+
return { first, last };
|
|
88
71
|
}, [searchResults]);
|
|
89
|
-
|
|
90
72
|
const [active = bounds.first, setActive] = useState();
|
|
91
|
-
|
|
92
73
|
useEffect(() => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
controller.abort();
|
|
118
|
-
};
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
setStatus("loading");
|
|
76
|
+
setSearchError(void 0);
|
|
77
|
+
const fetchResults = async () => {
|
|
78
|
+
try {
|
|
79
|
+
const results = await config.source(searchTerm || void 0, {
|
|
80
|
+
signal: controller.signal
|
|
81
|
+
});
|
|
82
|
+
if (!controller.signal.aborted) {
|
|
83
|
+
setActive(void 0);
|
|
84
|
+
setSearchError(void 0);
|
|
85
|
+
setSearchResults(normalizeChoices(results));
|
|
86
|
+
setStatus("idle");
|
|
87
|
+
}
|
|
88
|
+
} catch (error2) {
|
|
89
|
+
if (!controller.signal.aborted && error2 instanceof Error) {
|
|
90
|
+
setSearchError(error2.message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
void fetchResults();
|
|
95
|
+
return () => {
|
|
96
|
+
controller.abort();
|
|
97
|
+
};
|
|
119
98
|
}, [searchTerm]);
|
|
120
99
|
const selectedChoice = searchResults[active];
|
|
121
|
-
|
|
122
100
|
useKeypress(async (key, rl) => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
rl.write(selectedChoice.name);
|
|
135
|
-
setSearchTerm(selectedChoice.name);
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
rl.write(searchTerm);
|
|
139
|
-
}
|
|
140
|
-
} else if (key.name === 'tab' && selectedChoice) {
|
|
141
|
-
rl.clearLine(0);
|
|
101
|
+
if (isEnterKey(key)) {
|
|
102
|
+
if (selectedChoice) {
|
|
103
|
+
setStatus("loading");
|
|
104
|
+
const isValid = await validate(selectedChoice.value);
|
|
105
|
+
setStatus("idle");
|
|
106
|
+
if (isValid === true) {
|
|
107
|
+
setStatus("done");
|
|
108
|
+
done(selectedChoice.value);
|
|
109
|
+
} else if (selectedChoice.name === searchTerm) {
|
|
110
|
+
setSearchError(isValid || "You must provide a valid value");
|
|
111
|
+
} else {
|
|
142
112
|
rl.write(selectedChoice.name);
|
|
143
113
|
setSearchTerm(selectedChoice.name);
|
|
144
|
-
|
|
145
|
-
rl.clearLine(0);
|
|
146
|
-
if (key.name === 'up' && active !== bounds.first || key.name === 'down' && active !== bounds.last) {
|
|
147
|
-
const offset = key.name === 'up' ? -1 : 1;
|
|
148
|
-
let next = active;
|
|
149
|
-
|
|
150
|
-
do {
|
|
151
|
-
next = (next + offset + searchResults.length) % searchResults.length;
|
|
152
|
-
} while (!isSelectable(searchResults[next]))
|
|
153
|
-
setActive(next);
|
|
154
|
-
}
|
|
114
|
+
}
|
|
155
115
|
} else {
|
|
156
|
-
|
|
116
|
+
rl.write(searchTerm);
|
|
117
|
+
}
|
|
118
|
+
} else if (key.name === "tab" && selectedChoice) {
|
|
119
|
+
rl.clearLine(0);
|
|
120
|
+
rl.write(selectedChoice.name);
|
|
121
|
+
setSearchTerm(selectedChoice.name);
|
|
122
|
+
} else if (status !== "loading" && (key.name === "up" || key.name === "down")) {
|
|
123
|
+
rl.clearLine(0);
|
|
124
|
+
if (key.name === "up" && active !== bounds.first || key.name === "down" && active !== bounds.last) {
|
|
125
|
+
const offset = key.name === "up" ? -1 : 1;
|
|
126
|
+
let next = active;
|
|
127
|
+
do {
|
|
128
|
+
next = (next + offset + searchResults.length) % searchResults.length;
|
|
129
|
+
} while (!isSelectable(searchResults[next]));
|
|
130
|
+
setActive(next);
|
|
157
131
|
}
|
|
158
|
-
|
|
132
|
+
} else {
|
|
133
|
+
setSearchTerm(rl.line);
|
|
134
|
+
}
|
|
159
135
|
});
|
|
160
136
|
const message = theme.style.message(config.message, status);
|
|
161
|
-
|
|
162
137
|
if (active > 0) {
|
|
163
|
-
|
|
138
|
+
firstRender.current = false;
|
|
164
139
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
${theme.style.help('(Use arrow keys to reveal more choices)')}` : `
|
|
171
|
-
${theme.style.help('(Use arrow keys)')}`;
|
|
140
|
+
let helpTip = "";
|
|
141
|
+
if (searchResults.length > 1 && (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current)) {
|
|
142
|
+
helpTip = searchResults.length > pageSize ? `
|
|
143
|
+
${theme.style.help("(Use arrow keys to reveal more choices)")}` : `
|
|
144
|
+
${theme.style.help("(Use arrow keys)")}`;
|
|
172
145
|
}
|
|
173
|
-
|
|
174
146
|
const page = usePagination({
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
},
|
|
192
|
-
pageSize,
|
|
193
|
-
loop: false,
|
|
147
|
+
items: searchResults,
|
|
148
|
+
active,
|
|
149
|
+
renderItem({ item, isActive }) {
|
|
150
|
+
if (Separator.isSeparator(item)) {
|
|
151
|
+
return ` ${item.separator}`;
|
|
152
|
+
}
|
|
153
|
+
if (item.disabled) {
|
|
154
|
+
const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
|
|
155
|
+
return theme.style.disabled(`${item.name} ${disabledLabel}`);
|
|
156
|
+
}
|
|
157
|
+
const color = isActive ? theme.style.highlight : (x) => x;
|
|
158
|
+
const cursor = isActive ? theme.icon.cursor : ` `;
|
|
159
|
+
return color(`${cursor} ${item.name}`);
|
|
160
|
+
},
|
|
161
|
+
pageSize,
|
|
162
|
+
loop: false
|
|
194
163
|
});
|
|
195
|
-
|
|
196
164
|
let error;
|
|
197
|
-
|
|
198
165
|
if (searchError) {
|
|
199
|
-
|
|
200
|
-
} else if (
|
|
201
|
-
|
|
166
|
+
error = theme.style.error(searchError);
|
|
167
|
+
} else if (searchResults.length === 0 && searchTerm !== "" && status === "idle") {
|
|
168
|
+
error = theme.style.error("No results found");
|
|
202
169
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
170
|
let searchStr;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
171
|
+
if (status === "done" && selectedChoice) {
|
|
172
|
+
const answer = selectedChoice.short;
|
|
173
|
+
return `${prefix} ${message} ${theme.style.answer(answer)}`;
|
|
174
|
+
} else {
|
|
175
|
+
searchStr = theme.style.searchTerm(searchTerm);
|
|
210
176
|
}
|
|
211
|
-
|
|
212
|
-
searchStr = theme.style.searchTerm(searchTerm);
|
|
213
|
-
|
|
214
177
|
const choiceDescription = selectedChoice?.description ? `
|
|
215
178
|
${theme.style.description(selectedChoice.description)}` : ``;
|
|
216
|
-
|
|
217
179
|
return [
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
message,
|
|
221
|
-
searchStr,
|
|
222
|
-
]
|
|
223
|
-
.filter(Boolean)
|
|
224
|
-
.join(' '),
|
|
225
|
-
`${error ?? page}${helpTip}${choiceDescription}`,
|
|
180
|
+
[prefix, message, searchStr].filter(Boolean).join(" "),
|
|
181
|
+
`${error ?? page}${helpTip}${choiceDescription}`
|
|
226
182
|
];
|
|
227
|
-
}
|
|
228
|
-
|
|
183
|
+
}
|
|
184
|
+
);
|
|
229
185
|
export default search;
|
|
230
|
-
|
|
231
|
-
export {Separator} from '../../components/core/index.js';
|
|
186
|
+
export { Separator } from "../../components/core/index.js";
|