Skip to content

Commit

Permalink
fix(prompt): wrong cursor position on windows (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Nov 24, 2020
1 parent 6a088bd commit 0e14b51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions prompt/_generic_input.ts
Expand Up @@ -66,13 +66,13 @@ export abstract class GenericInput<T, S extends GenericInputPromptSettings<T>>
protected setPrompt(message: string) {
message += " " + this.settings.pointer + " ";

const length = new TextEncoder().encode(stripColor(message)).length;
const length = stripColor(message).length;

message += underline(this.input);

this.write(message);

this.screen.cursorTo(length - 1 + this.index);
this.screen.cursorTo(length + this.index + 1);
}

/**
Expand Down Expand Up @@ -146,7 +146,6 @@ export abstract class GenericInput<T, S extends GenericInputPromptSettings<T>>
/** Move prompt cursor right. */
protected moveCursorRight(): void {
if (this.index < this.input.length) {
const index = this.input.indexOf(" ", this.index);
this.index++;
}
}
Expand Down
6 changes: 3 additions & 3 deletions prompt/figures.ts
Expand Up @@ -22,10 +22,10 @@ const win = {
RADIO_OFF: "( )",
TICK: "√",
CROSS: "×",
ELLIPSIS: "...",
ELLIPSIS: main.ELLIPSIS,
POINTER_SMALL: "»",
LINE: "─",
POINTER: ">",
LINE: main.LINE,
POINTER: main.POINTER,
};

/** Prompt icons. */
Expand Down

0 comments on commit 0e14b51

Please sign in to comment.