Skip to content

Commit 4006972

Browse files
committed
feat: add styles
1 parent f3892f7 commit 4006972

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/utils/styles/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ export const confirm = (opts: ConfirmOptions) => {
133133
type Primitive = Readonly<string | boolean | number>
134134

135135
type Option<Value> = Value extends Primitive
136-
? { value: Value; label?: string; hint?: string }
137-
: { value: Value; label: string; hint?: string }
136+
? { value: Value; label?: string; hint?: string; group?: string | true }
137+
: { value: Value; label: string; hint?: string; group?: string | true }
138138

139139
export interface SelectOptions<Value> {
140140
message: string
@@ -184,6 +184,7 @@ export const select = <Value>(opts: SelectOptions<Value>) => {
184184
}).prompt() as Promise<Value>
185185
}
186186

187+
// allows for the use of a) b) c) etc. options.
187188
export const selectKey = <Value extends string>(opts: SelectOptions<Value>) => {
188189
const renderOption = (
189190
option: Option<Value>,
@@ -211,13 +212,12 @@ export const selectKey = <Value extends string>(opts: SelectOptions<Value>) => {
211212
initialValue: opts.initialValue,
212213
render() {
213214
const title = `${chalk.gray(symbols.BAR)}\n${coloredSymbol(this.state)} ${opts.message}\n`
215+
const selectedOption = this.options.find((opt: { value: string }) => opt.value === this.value)
216+
if (!selectedOption) return
214217

215218
switch (this.state) {
216219
case 'submit': {
217-
return `${title}${chalk.gray(symbols.BAR)} ${renderOption(
218-
this.options.find((opt) => opt.value === this.value)!,
219-
'selected',
220-
)}`
220+
return `${title}${chalk.gray(symbols.BAR)} ${renderOption(selectedOption, 'selected')}`
221221
}
222222
case 'cancel':
223223
return `${title}${chalk.gray(symbols.BAR)} ${renderOption(this.options[0], 'cancelled')}\n${chalk.gray(
@@ -357,9 +357,9 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
357357
options: Option<Value>[] = [],
358358
) => {
359359
const label = option.label ?? String(option.value)
360-
const isItem = typeof (option as any).group === 'string'
360+
const isItem = typeof option.group === 'string'
361361
const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true })
362-
const isLast = isItem && (next as any).group === true
362+
const isLast = isItem && next && next.group === true
363363
const prefix = isItem ? `${isLast ? symbols.BAR_END : symbols.BAR} ` : ''
364364

365365
if (state === 'active') {

0 commit comments

Comments
 (0)