Skip to content

Commit

Permalink
Swap out clearLine() with readline
Browse files Browse the repository at this point in the history
  • Loading branch information
targoninc-alex committed Apr 20, 2024
1 parent 87f401d commit b262818
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions api/CLI.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import readline from "readline";

export class CLI {
static color(text, color, newLine = true) {
process.stdout.write(`\x1b[${color}m${text}\x1b[0m${newLine ? "\n" : ""}`);
Expand Down Expand Up @@ -37,14 +39,20 @@ export class CLI {
}
}

static rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});

static rewrite(text) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(text);
readline.clearLine(CLI.rl, 0);
readline.cursorTo(CLI.rl, 0);
this.rl.write(text);
}

static clear() {
process.stdout.clearLine();
process.stdout.cursorTo(0);
readline.clearLine(CLI.rl, 0);
readline.cursorTo(CLI.rl, 0);
}
}

0 comments on commit b262818

Please sign in to comment.