| 12 | |
| 13 | export const selectKey = <Value extends string>(opts: SelectKeyOptions<Value>) => { |
| 14 | const opt = ( |
| 15 | option: Option<Value>, |
| 16 | state: 'inactive' | 'active' | 'selected' | 'cancelled' = 'inactive' |
| 17 | ) => { |
| 18 | const label = option.label ?? String(option.value); |
| 19 | if (state === 'selected') { |
| 20 | return `${styleText('dim', label)}`; |
| 21 | } |
| 22 | if (state === 'cancelled') { |
| 23 | return `${styleText(['strikethrough', 'dim'], label)}`; |
| 24 | } |
| 25 | if (state === 'active') { |
| 26 | return `${styleText(['bgCyan', 'gray'], ` ${option.value} `)} ${label}${ |
| 27 | option.hint ? ` ${styleText('dim', `(${option.hint})`)}` : '' |
| 28 | }`; |
| 29 | } |
| 30 | return `${styleText(['gray', 'bgWhite', 'inverse'], ` ${option.value} `)} ${label}${ |
| 31 | option.hint ? ` ${styleText('dim', `(${option.hint})`)}` : '' |
| 32 | }`; |
| 33 | }; |
| 34 | |
| 35 | return new SelectKeyPrompt({ |
| 36 | options: opts.options, |