@@ -61187,22 +61187,36 @@ function normalizeChoices3(choices) {
6118761187 };
6118861188 });
6118961189}
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+ }
6119061201var esm_default8 = createPrompt((config2, done) => {
61202+ const { loop = true } = config2;
6119161203 const choices = useMemo(() => normalizeChoices3(config2.choices), [config2.choices]);
6119261204 const [status, setStatus] = useState("idle");
6119361205 const [value, setValue] = useState("");
6119461206 const [errorMsg, setError] = useState();
6119561207 const theme = makeTheme(config2.theme);
6119661208 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]);
6119761217 useKeypress((key, rl) => {
6119861218 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);
6120661220 if (isSelectableChoice(selectedChoice)) {
6120761221 setValue(selectedChoice.short);
6120861222 setStatus("done");
@@ -61212,6 +61226,20 @@ var esm_default8 = createPrompt((config2, done) => {
6121261226 } else {
6121361227 setError(`"${import_yoctocolors_cjs5.default.red(value)}" isn't an available option`);
6121461228 }
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+ }
6121561243 } else {
6121661244 setValue(rl.line);
6121761245 setError(void 0);
@@ -61498,6 +61526,7 @@ function normalizeChoices5(choices) {
6149861526 });
6149961527}
6150061528var esm_default11 = createPrompt((config2, done) => {
61529+ var _a, _b;
6150161530 const { loop = true, pageSize = 7 } = config2;
6150261531 const firstRender = useRef(true);
6150361532 const theme = makeTheme(selectTheme, config2.theme);
@@ -61571,9 +61600,9 @@ var esm_default11 = createPrompt((config2, done) => {
6157161600 firstRender.current = false;
6157261601 if (items.length > pageSize) {
6157361602 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"})` )}`;
6157561604 } 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"})` );
6157761606 }
6157861607 }
6157961608 const page = usePagination({
0 commit comments