-
Notifications
You must be signed in to change notification settings - Fork 158
Description
Is your feature request related to a problem? Please describe.
Current implementation lowercases option keys and prevents ability to use distinct lowercase and uppercase keys. This makes common CLI patterns impossible (e.g. 'a' = accept, 'A' = accept all).
Side note: the initialValue lookup is also compared against the un-normalized value, which can place the cursor incorrectly. (see code below)
Describe the solution you'd like
Add support for case-sensitive key matching by removing the lowercasing normalization so comparisons are exact (case-sensitive).
If this is too invasive, consider adding an option to opt into this behavior.
Additional context
I believe this is where everything is normalized to lowercase:
clack/packages/core/src/prompts/select-key.ts
Lines 7 to 28 in 372b526
| export default class SelectKeyPrompt<T extends { value: string }> extends Prompt<T['value']> { | |
| options: T[]; | |
| cursor = 0; | |
| constructor(opts: SelectKeyOptions<T>) { | |
| super(opts, false); | |
| this.options = opts.options; | |
| const keys = this.options.map(({ value: [initial] }) => initial?.toLowerCase()); | |
| this.cursor = Math.max(keys.indexOf(opts.initialValue), 0); | |
| this.on('key', (key) => { | |
| if (!key || !keys.includes(key)) return; | |
| const value = this.options.find(({ value: [initial] }) => initial?.toLowerCase() === key); | |
| if (value) { | |
| this.value = value.value; | |
| this.state = 'submit'; | |
| this.emit('submit'); | |
| } | |
| }); | |
| } | |
| } |
Metadata
Metadata
Assignees
Labels
Type
Projects
Status