Skip to content

Commit

Permalink
refactor(prompt): revert clear behavior (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Nov 27, 2020
1 parent d116c73 commit b5ecced
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion prompt/_generic_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export abstract class GenericInput<T, S extends GenericInputPromptSettings<T>>

message += underline(this.input);

this.clear();
this.write(message);

this.screen.cursorTo(length + this.index + 1);
Expand Down
1 change: 0 additions & 1 deletion prompt/_generic_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export abstract class GenericList<T, V, S extends GenericListSettings<T, V>>
* @param message Prompt message.
*/
protected render(message: string): void {
this.clear();
this.writeLine(message);
this.writeListItems();
}
Expand Down
9 changes: 8 additions & 1 deletion prompt/_generic_prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export abstract class GenericPrompt<

protected screen = AnsiEscape.from(Deno.stdout);
protected lastError: string | undefined;
protected isRunning = false;
protected value: T | undefined;

/**
Expand Down Expand Up @@ -105,14 +106,19 @@ export abstract class GenericPrompt<
protected abstract getValue(): V;

/** Clear prompt output. */
protected clear() {
protected clear(): void {
this.screen
.cursorLeft()
.eraseDown();
}

/** Execute the prompt. */
protected async execute(): Promise<T> {
if (this.lastError || this.isRunning) {
this.clear();
}
this.isRunning = true;

const message: string = await this.getMessage();
// be sure there are empty lines after the cursor to fix restoring the
// cursor if terminal output is longer than terminal window.
Expand Down Expand Up @@ -146,6 +152,7 @@ export abstract class GenericPrompt<
this.screen.cursorShow();

GenericPrompt.injectedValue = undefined;
this.isRunning = false;

return this.value;
}
Expand Down
1 change: 0 additions & 1 deletion prompt/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class List extends GenericInput<string[], ListSettings> {
this.input = oldInputParts.join(separator);
this.index -= oldInput.length - this.input.length;

this.clear();
this.write(message);

this.screen.cursorTo(length - 1 + this.index);
Expand Down
1 change: 0 additions & 1 deletion prompt/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class Secret extends GenericInput<string, SecretSettings> {

message += underline(secret);

this.clear();
this.write(message);

this.screen.cursorTo(length - 1 + this.index);
Expand Down
1 change: 0 additions & 1 deletion prompt/toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export class Toggle extends GenericPrompt<boolean, string, ToggleSettings> {
message += dim(this.settings.inactive + " / " + this.settings.active);
}

this.clear();
this.write(message);
}

Expand Down

0 comments on commit b5ecced

Please sign in to comment.