MCPcopy
hub / github.com/bombshell-dev/clack / constructor

Method constructor

packages/core/src/prompts/select.ts:23–46  ·  view source on GitHub ↗
(opts: SelectOptions<T>)

Source from the content-addressed store, hash-verified

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 3

changeValueMethod · 0.95
findCursorFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected