MCPcopy Create free account
hub / github.com/denoland/std / promptSelect

Function promptSelect

cli/unstable_prompt_select.ts:108–161  ·  view source on GitHub ↗
(
  message: string,
  values: PromptEntry<V>[],
  options: PromptSelectOptions = {},
)

Source from the content-addressed store, hash-verified

106 * ```
107 */
108export function promptSelect<V = undefined>(
109 message: string,
110 values: PromptEntry<V>[],
111 options: PromptSelectOptions = {},
112): PromptEntry<V> | null {
113 if (!Deno.stdin.isTerminal()) return null;
114
115 let selectedIndex = 0;
116
117 handlePromptSelect(
118 message,
119 options.indicator ?? "❯",
120 values,
121 options.clear,
122 options.visibleLines,
123 options.fitToRemainingHeight,
124 (active, absoluteIndex) => {
125 if (active) {
126 selectedIndex = absoluteIndex;
127 }
128 },
129 (str, _absoluteIndex, {
130 etx,
131 up,
132 down,
133 remove,
134 inputStr,
135 }) => {
136 switch (str) {
137 case ETX:
138 return etx();
139 case ARROW_UP:
140 up();
141 break;
142 case ARROW_DOWN:
143 down();
144 break;
145 case CR:
146 case " ":
147 return true;
148 case DELETE:
149 remove();
150 break;
151 default:
152 inputStr();
153 break;
154 }
155
156 return false;
157 },
158 );
159
160 return values[selectedIndex] ?? null;
161}

Callers 1

Calls 3

handlePromptSelectFunction · 0.90
removeFunction · 0.85
isTerminalMethod · 0.65

Tested by

no test coverage detected