@@ -61187,22 +61187,36 @@ function normalizeChoices3(choices) {
61187
61187
};
61188
61188
});
61189
61189
}
61190
+ function getSelectedChoice(input, choices) {
61191
+ let selectedChoice;
61192
+ const selectableChoices = choices.filter(isSelectableChoice);
61193
+ if (numberRegex.test(input)) {
61194
+ const answer = Number.parseInt(input, 10) - 1;
61195
+ selectedChoice = selectableChoices[answer];
61196
+ } else {
61197
+ selectedChoice = selectableChoices.find((choice) => choice.key === input);
61198
+ }
61199
+ return selectedChoice ? [selectedChoice, choices.indexOf(selectedChoice)] : [void 0, void 0];
61200
+ }
61190
61201
var esm_default8 = createPrompt((config2, done) => {
61202
+ const { loop = true } = config2;
61191
61203
const choices = useMemo(() => normalizeChoices3(config2.choices), [config2.choices]);
61192
61204
const [status, setStatus] = useState("idle");
61193
61205
const [value, setValue] = useState("");
61194
61206
const [errorMsg, setError] = useState();
61195
61207
const theme = makeTheme(config2.theme);
61196
61208
const prefix = usePrefix({ status, theme });
61209
+ const bounds = useMemo(() => {
61210
+ const first = choices.findIndex(isSelectableChoice);
61211
+ const last = choices.findLastIndex(isSelectableChoice);
61212
+ if (first === -1) {
61213
+ throw new ValidationError("[select prompt] No selectable choices. All choices are disabled.");
61214
+ }
61215
+ return { first, last };
61216
+ }, [choices]);
61197
61217
useKeypress((key, rl) => {
61198
61218
if (isEnterKey(key)) {
61199
- let selectedChoice;
61200
- if (numberRegex.test(value)) {
61201
- const answer = Number.parseInt(value, 10) - 1;
61202
- selectedChoice = choices.filter(isSelectableChoice)[answer];
61203
- } else {
61204
- selectedChoice = choices.find((choice) => isSelectableChoice(choice) && choice.key === value);
61205
- }
61219
+ const [selectedChoice] = getSelectedChoice(value, choices);
61206
61220
if (isSelectableChoice(selectedChoice)) {
61207
61221
setValue(selectedChoice.short);
61208
61222
setStatus("done");
@@ -61212,6 +61226,20 @@ var esm_default8 = createPrompt((config2, done) => {
61212
61226
} else {
61213
61227
setError(`"${import_yoctocolors_cjs5.default.red(value)}" isn't an available option`);
61214
61228
}
61229
+ } else if (key.name === "up" || key.name === "down") {
61230
+ rl.clearLine(0);
61231
+ const [selectedChoice, active] = getSelectedChoice(value, choices);
61232
+ if (!selectedChoice) {
61233
+ const firstChoice = key.name === "down" ? choices.find(isSelectableChoice) : choices.findLast(isSelectableChoice);
61234
+ setValue(firstChoice.key);
61235
+ } else if (loop || key.name === "up" && active !== bounds.first || key.name === "down" && active !== bounds.last) {
61236
+ const offset = key.name === "up" ? -1 : 1;
61237
+ let next = active;
61238
+ do {
61239
+ next = (next + offset + choices.length) % choices.length;
61240
+ } while (!isSelectableChoice(choices[next]));
61241
+ setValue(choices[next].key);
61242
+ }
61215
61243
} else {
61216
61244
setValue(rl.line);
61217
61245
setError(void 0);
@@ -61498,6 +61526,7 @@ function normalizeChoices5(choices) {
61498
61526
});
61499
61527
}
61500
61528
var esm_default11 = createPrompt((config2, done) => {
61529
+ var _a, _b;
61501
61530
const { loop = true, pageSize = 7 } = config2;
61502
61531
const firstRender = useRef(true);
61503
61532
const theme = makeTheme(selectTheme, config2.theme);
@@ -61571,9 +61600,9 @@ var esm_default11 = createPrompt((config2, done) => {
61571
61600
firstRender.current = false;
61572
61601
if (items.length > pageSize) {
61573
61602
helpTipBottom = `
61574
- ${theme.style.help("( Use arrow keys to reveal more choices)" )}`;
61603
+ ${theme.style.help(`(${((_a = config2.instructions) == null ? void 0 : _a.pager) ?? " Use arrow keys to reveal more choices"})` )}`;
61575
61604
} else {
61576
- helpTipTop = theme.style.help("( Use arrow keys)" );
61605
+ helpTipTop = theme.style.help(`(${((_b = config2.instructions) == null ? void 0 : _b.navigation) ?? " Use arrow keys"})` );
61577
61606
}
61578
61607
}
61579
61608
const page = usePagination({
0 commit comments