Skip to content

Commit

Permalink
feat(plugin-inquirer): add separator option for checkbox multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhengqbbb committed May 11, 2022
1 parent 26b54c5 commit 3eaab45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/@cz-git/plugin-inquirer/src/checkbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export class SearchCheckbox extends Base {
private initialValue: any = -1;
private lastSearchInput?: string;
private paginator: Paginator = new Paginator(this.screen, { isInfinite: true });
private separator = " ,";
private answer?: boolean;
private done: any;

constructor(questions: Question, readline: ReadlineInterface, answers: Answers) {
super(questions, readline, answers);

const { source, isInitDefault } = this.opt as unknown as CZPromptQuestionOptions;
const { source, separator, isInitDefault } = this.opt as unknown as CZPromptQuestionOptions;
if (!source) this.throwParamError("source");
if (typeof separator === "string") this.separator = separator;
if (isInitDefault) this.initialValue = this.opt.default;
this.renderChoices = new Choices([], {});
}
Expand Down Expand Up @@ -71,7 +72,7 @@ export class SearchCheckbox extends Base {

// Render choices or answer depending on the state
if (this.status === "answered") {
content += style.cyan(this.selection.join(", "));
content += style.cyan(this.selection.join(this.separator));
} else if (this.searching) {
content += this.rl.line;
bottomContent += " " + style.dim("Searching...");
Expand Down Expand Up @@ -221,7 +222,7 @@ export class SearchCheckbox extends Base {
this.answer = true;
this.render();
this.screen.done();
this.done(isCustom ? choices[0] : this.selection);
this.done(isCustom ? choices[0].value : this.selection);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/@cz-git/plugin-inquirer/src/shared/types/inquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface CZPromptOptionType extends BaseOptionType {
isInitDefault: boolean;
}
export interface CZPromptQuestionOptions<T extends Answers = Answers> extends Question<T> {
separator: string;

/**
* Function to determine what options to display to user.
* Called with previous answers object and the current user input each time the user types, it must return a promise.
Expand Down

0 comments on commit 3eaab45

Please sign in to comment.