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

Function opt

packages/prompts/src/select.ts:97–118  ·  view source on GitHub ↗
(
		option: Option<Value>,
		state: 'inactive' | 'active' | 'selected' | 'cancelled' | 'disabled'
	)

Source from the content-addressed store, hash-verified

95
96export const select = <Value>(opts: SelectOptions<Value>) => {
97 const opt = (
98 option: Option<Value>,
99 state: 'inactive' | 'active' | 'selected' | 'cancelled' | 'disabled'
100 ) => {
101 const label = option.label ?? String(option.value);
102 switch (state) {
103 case 'disabled':
104 return `${styleText('gray', S_RADIO_INACTIVE)} ${computeLabel(label, (text) => styleText('gray', text))}${
105 option.hint ? ` ${styleText('dim', `(${option.hint ?? 'disabled'})`)}` : ''
106 }`;
107 case 'selected':
108 return `${computeLabel(label, (text) => styleText('dim', text))}`;
109 case 'active':
110 return `${styleText('green', S_RADIO_ACTIVE)} ${label}${
111 option.hint ? ` ${styleText('dim', `(${option.hint})`)}` : ''
112 }`;
113 case 'cancelled':
114 return `${computeLabel(label, (str) => styleText(['strikethrough', 'dim'], str))}`;
115 default:
116 return `${styleText('dim', S_RADIO_INACTIVE)} ${computeLabel(label, (text) => styleText('dim', text))}`;
117 }
118 };
119
120 const showInstructions = opts.showInstructions ?? true;
121

Callers 1

renderFunction · 0.70

Calls 1

computeLabelFunction · 0.70

Tested by

no test coverage detected