Skip to content

Commit b7e1bf5

Browse files
fix(cli): allow selecting commands with enter but still type messages
1 parent c031700 commit b7e1bf5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

bin/cli.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,25 @@ async function conversation() {
9191
message: 'Write a message:',
9292
searchText: '​',
9393
emptyText: '​',
94-
source: (answers, input) => {
95-
return Promise.resolve(
96-
input ? availableCommands.filter((command) => command.value.startsWith(input)) : []
97-
);
98-
}
94+
suggestOnly: true,
95+
validate: (choice, answers) => {
96+
return true;
97+
},
98+
source: () => Promise.resolve([]),
9999
},
100100
]);
101101
// hiding the ugly autocomplete hint
102102
prompt.ui.activePrompt.firstRender = false;
103+
// The below is a hack to allow selecting items from the autocomplete menu while also being able to submit messages.
104+
// This basically simulates a hybrid between having `suggestOnly: false` and `suggestOnly: true`.
105+
await new Promise((resolve) => setTimeout(resolve, 0));
106+
prompt.ui.activePrompt.opt.source = (answers, input) => {
107+
if (!input) {
108+
return [];
109+
}
110+
prompt.ui.activePrompt.opt.suggestOnly = !input.startsWith('!');
111+
return availableCommands.filter((command) => command.value.startsWith(input));
112+
};
103113
let { message } = await prompt;
104114
message = message.trim();
105115
if (!message) {

0 commit comments

Comments
 (0)