Skip to content

Commit

Permalink
feat(prompt): add info option to all prompts with a select or suggest…
Browse files Browse the repository at this point in the history
…ions list
  • Loading branch information
c4spar committed Dec 28, 2020
1 parent 44575e3 commit c7bfce6
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions prompt/_generic_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
GenericInputPromptOptions,
GenericInputPromptSettings,
} from "./_generic_input.ts";
import { bold, dim, stripColor, yellow } from "./deps.ts";
import { blue, bold, dim, stripColor, yellow } from "./deps.ts";
import { Figures } from "./figures.ts";

/** Select key options. */
export interface GenericListKeys extends GenericInputKeys {
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface GenericListOptions<T, V>
maxRows?: number;
searchLabel?: string;
search?: boolean;
info?: boolean;
}

/** Generic list prompt settings. */
Expand All @@ -57,6 +59,7 @@ export interface GenericListSettings<T, V>
maxRows: number;
searchLabel: string;
search?: boolean;
info?: boolean;
}

/** Generic list prompt representation. */
Expand Down Expand Up @@ -135,12 +138,29 @@ export abstract class GenericList<T, V, S extends GenericListSettings<T, V>>

/** Render options. */
protected body(): string | Promise<string> {
return this.getList();
// let body: string = this.getOptionsList();
// if (this.settings.info) {
// body += "\n" + this.getInfo();
// }
// return body;
return this.getList() + this.getInfo();
}

protected getInfo(): string {
if (!this.settings.info) {
return "";
}
const selected: number = this.listIndex + 1;
const actions: Array<[string, Array<string>]> = [];

actions.push(
["Next", [Figures.ARROW_DOWN]],
["Previous", [Figures.ARROW_UP]],
["Next Page", [Figures.PAGE_DOWN]],
["Previous Page", [Figures.PAGE_UP]],
["Submit", [Figures.ENTER]],
);

return "\n" + this.settings.indent + blue(Figures.INFO) +
bold(` ${selected}/${this.options.length} `) +
actions
.map((cur) => `${cur[0]}: ${bold(cur[1].join(" "))}`)
.join(", ");
}

/** Render options list. */
Expand Down

0 comments on commit c7bfce6

Please sign in to comment.