Skip to content

Commit

Permalink
Fix suggest/choices params terkelg#98
Browse files Browse the repository at this point in the history
  • Loading branch information
elie-g authored and terkelg committed Oct 20, 2018
1 parent 82be92d commit ce26493
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/elements/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class AutocompletePrompt extends Prompt {
const suggestions = await p;

if (this.completing !== p) return;

this.suggestions = suggestions.slice(0, this.limit).map(s => strip(s));
this.suggestions = suggestions.slice(0, this.limit)
.map((s, i, arr) => ({title: getTitle(arr, i), value: getVal(arr, i)}));
this.completing = false;

const l = Math.max(suggestions.length - 1, 0);
Expand Down Expand Up @@ -170,15 +170,15 @@ class AutocompletePrompt extends Prompt {
if (this.done && this.suggestions[this.select]) {
prompt += `${this.suggestions[this.select].title}`;
} else {
this.rendered = `${this.transform.render(this.input)}`
this.rendered = `${this.transform.render(this.input)}`;
length += this.rendered.length;
prompt += this.rendered;
}

if (!this.done) {
this.lineCount = this.suggestions.length;
let suggestions = this.suggestions.reduce((acc, item, i) =>
acc += `\n${i === this.select ? color.cyan(item.title) : item.title}`, '');
acc + `\n${i === this.select ? color.cyan(item.title) : item.title}`, '');
if (suggestions) {
prompt += suggestions;
} else {
Expand Down
6 changes: 5 additions & 1 deletion lib/elements/multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class MultiselectPrompt extends Prompt {
this.cursor = opts.cursor || 0;
this.hint = opts.hint || '- Space to select. Return to submit';
this.maxChoices = opts.max;
this.value = opts.choices.map(v => Object.assign({ title: v.value, selected: false }, v));
this.value = opts.choices.map(v => ({
title: v && (v.title || v.value || v),
value: typeof v === 'object' ? v.value : v,
selected: v && v.selected
}));
this.clear = clear('');
this.render(true);
}
Expand Down
6 changes: 5 additions & 1 deletion lib/elements/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ class SelectPrompt extends Prompt {
this.msg = opts.message;
this.hint = opts.hint || '- Use arrow-keys. Return to submit.';
this.cursor = opts.initial || 0;
this.values = opts.choices || [];
this.values = opts.choices.map((v, i) => ({
title: v && (v.title || v.value || v),
value: typeof v === 'object' ? v.value : v,
selected: v && v.selected
}));
this.value = opts.choices[this.cursor].value;
this.clear = clear('');
this.render(true);
Expand Down

0 comments on commit ce26493

Please sign in to comment.