( option: Option<Value>, state: 'inactive' | 'active' | 'selected' | 'cancelled' | 'disabled' )
| 95 | |
| 96 | export 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 |
no test coverage detected