Skip to content

Commit 3600b40

Browse files
committed
fix: fix autocomplete bar color when validate
1 parent 9b92161 commit 3600b40

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

packages/prompts/src/autocomplete.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export const autocomplete = <Value>(opts: AutocompleteOptions<Value>) => {
112112
}
113113

114114
default: {
115+
const barColor = this.state === "error" ? color.yellow : color.cyan;
115116
// Display cursor position - show plain text in navigation mode
116117
let searchText = '';
117118
if (this.isNavigating || showPlaceholder) {
@@ -132,15 +133,15 @@ export const autocomplete = <Value>(opts: AutocompleteOptions<Value>) => {
132133
// No matches message
133134
const noResults =
134135
this.filteredOptions.length === 0 && userInput
135-
? [`${color.cyan(S_BAR)} ${color.yellow('No matches found')}`]
136+
? [`${barColor(S_BAR)} ${color.yellow('No matches found')}`]
136137
: [];
137138

138139
const validationError =
139-
this.state === 'error' ? [`${color.yellow(S_BAR)} ${color.yellow(this.error)}`] : [];
140+
this.state === 'error' ? [`${barColor(S_BAR)} ${color.yellow(this.error)}`] : [];
140141

141142
headings.push(
142-
`${color.cyan(S_BAR)}`,
143-
`${color.cyan(S_BAR)} ${color.dim('Search:')}${searchText}${matches}`,
143+
`${barColor(S_BAR)}`,
144+
`${barColor(S_BAR)} ${color.dim('Search:')}${searchText}${matches}`,
144145
...noResults,
145146
...validationError
146147
);
@@ -153,8 +154,8 @@ export const autocomplete = <Value>(opts: AutocompleteOptions<Value>) => {
153154
];
154155

155156
const footers = [
156-
`${color.cyan(S_BAR)} ${color.dim(instructions.join(' • '))}`,
157-
`${color.cyan(S_BAR_END)}`,
157+
`${barColor(S_BAR)} ${color.dim(instructions.join(' • '))}`,
158+
`${barColor(S_BAR_END)}`,
158159
];
159160

160161
// Render options with selection
@@ -184,7 +185,7 @@ export const autocomplete = <Value>(opts: AutocompleteOptions<Value>) => {
184185
// Return the formatted prompt
185186
return [
186187
...headings,
187-
...displayOptions.map((option) => `${color.cyan(S_BAR)} ${option}`),
188+
...displayOptions.map((option) => `${barColor(S_BAR)} ${option}`),
188189
...footers,
189190
].join('\n');
190191
}
@@ -282,6 +283,7 @@ export const autocompleteMultiselect = <Value>(opts: AutocompleteMultiSelectOpti
282283
return `${title}${color.gray(S_BAR)} ${color.strikethrough(color.dim(userInput))}`;
283284
}
284285
default: {
286+
const barColor = this.state === "error" ? color.yellow : color.cyan;
285287
// Instructions
286288
const instructions = [
287289
`${color.dim('↑/↓')} to navigate`,
@@ -293,22 +295,22 @@ export const autocompleteMultiselect = <Value>(opts: AutocompleteMultiSelectOpti
293295
// No results message
294296
const noResults =
295297
this.filteredOptions.length === 0 && userInput
296-
? [`${color.cyan(S_BAR)} ${color.yellow('No matches found')}`]
298+
? [`${barColor(S_BAR)} ${color.yellow('No matches found')}`]
297299
: [];
298300

299301
const errorMessage =
300-
this.state === 'error' ? [`${color.cyan(S_BAR)} ${color.yellow(this.error)}`] : [];
302+
this.state === 'error' ? [`${barColor(S_BAR)} ${color.yellow(this.error)}`] : [];
301303

302304
// Calculate header and footer line counts for rowPadding
303305
const headerLines = [
304306
...title.split('\n'),
305-
`${color.cyan(S_BAR)} ${color.dim('Search:')} ${searchText}${matches}`,
307+
`${barColor(S_BAR)} ${color.dim('Search:')} ${searchText}${matches}`,
306308
...noResults,
307309
...errorMessage,
308310
];
309311
const footerLines = [
310-
`${color.cyan(S_BAR)} ${color.dim(instructions.join(' • '))}`,
311-
`${color.cyan(S_BAR_END)}`,
312+
`${barColor(S_BAR)} ${color.dim(instructions.join(' • '))}`,
313+
`${barColor(S_BAR_END)}`,
312314
];
313315

314316
// Get limited options for display
@@ -325,7 +327,7 @@ export const autocompleteMultiselect = <Value>(opts: AutocompleteMultiSelectOpti
325327
// Build the prompt display
326328
return [
327329
...headerLines,
328-
...displayOptions.map((option) => `${color.cyan(S_BAR)} ${option}`),
330+
...displayOptions.map((option) => `${barColor(S_BAR)} ${option}`),
329331
...footerLines,
330332
].join('\n');
331333
}

0 commit comments

Comments
 (0)