Skip to content

Commit 53d7be0

Browse files
authored
refactor(cli): show key hints for multichoice promtps (#1392)
Closes #819
1 parent 787f427 commit 53d7be0

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/prompts/src/__tests__/__snapshots__/render.spec.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ exports[`prompt renderers > renders multiselect with cursor marker plus checkbox
5252
Second line
5353
› ◼ Beta
5454
◻ Gamma
55+
Press space to select, enter to submit
5556
5657
"
5758
`;

packages/prompts/src/multi-select.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
120120
);
121121
};
122122
const required = opts.required ?? true;
123+
const hint =
124+
' ' +
125+
color.reset(
126+
color.dim(
127+
`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(
128+
color.bgWhite(color.inverse(' enter ')),
129+
)} to submit`,
130+
),
131+
);
123132

124133
return new MultiSelectPrompt({
125134
options: opts.options,
@@ -131,13 +140,7 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
131140
cursorAt: opts.cursorAt,
132141
validate(selected: Value[] | undefined) {
133142
if (required && (selected === undefined || selected.length === 0)) {
134-
return `Please select at least one option.\n${color.reset(
135-
color.dim(
136-
`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(
137-
color.bgWhite(color.inverse(' enter ')),
138-
)} to submit`,
139-
),
140-
)}`;
143+
return `Please select at least one option.\n${hint}`;
141144
}
142145
return undefined;
143146
},
@@ -221,7 +224,7 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
221224
columnPadding: prefix.length,
222225
rowPadding: titleLineCount + footerLineCount,
223226
style: styleOption,
224-
}).join(`\n${prefix}`)}\n${footer}\n`;
227+
}).join(`\n${prefix}`)}\n${hint}\n${footer}\n`;
225228
}
226229
default: {
227230
const prefix = hasGuide ? `${color.blue(S_BAR)} ` : nestedPrefix;
@@ -236,7 +239,7 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
236239
columnPadding: prefix.length,
237240
rowPadding: titleLineCount + footerLineCount,
238241
style: styleOption,
239-
}).join(`\n${prefix}`)}\n${hasGuide ? color.blue(S_BAR_END) : ''}\n`;
242+
}).join(`\n${prefix}`)}\n${hint}\n${hasGuide ? color.blue(S_BAR_END) : ''}\n`;
240243
}
241244
}
242245
},

0 commit comments

Comments
 (0)