MCPcopy Create free account
hub / github.com/bombshell-dev/clack / SelectPrompt

Class SelectPrompt

packages/core/src/prompts/select.ts:9–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7 initialValue?: T['value'];
8}
9export default class SelectPrompt<T extends { value: any; disabled?: boolean }> extends Prompt<
10 T['value']
11> {
12 options: T[];
13 cursor = 0;
14
15 private get _selectedValue() {
16 return this.options[this.cursor];
17 }
18
19 private changeValue() {
20 this.value = this._selectedValue.value;
21 }
22
23 constructor(opts: SelectOptions<T>) {
24 super(opts, false);
25
26 this.options = opts.options;
27
28 const initialCursor = this.options.findIndex(({ value }) => value === opts.initialValue);
29 const cursor = initialCursor === -1 ? 0 : initialCursor;
30 this.cursor = this.options[cursor].disabled ? findCursor<T>(cursor, 1, this.options) : cursor;
31 this.changeValue();
32
33 this.on('cursor', (key) => {
34 switch (key) {
35 case 'left':
36 case 'up':
37 this.cursor = findCursor<T>(this.cursor, -1, this.options);
38 break;
39 case 'down':
40 case 'right':
41 this.cursor = findCursor<T>(this.cursor, 1, this.options);
42 break;
43 }
44 this.changeValue();
45 });
46 }
47}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected