Skip to content

Commit

Permalink
Revert "Improve performance of the .clear() method (sindresorhus#182)"
Browse files Browse the repository at this point in the history
This reverts commit d51c971.
  • Loading branch information
x71c9 committed Mar 15, 2022
1 parent 27d855d commit b4d879b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 579 deletions.
12 changes: 2 additions & 10 deletions index.js
Expand Up @@ -142,7 +142,6 @@ class Ora {
}

this._indent = indent;
this.updateLineCount();
}

_updateInterval(interval) {
Expand Down Expand Up @@ -216,7 +215,7 @@ class Ora {
const columns = this.stream.columns || 80;
const fullPrefixText = this.getFullPrefixText(this.prefixText, '-');
this.lineCount = 0;
for (const line of stripAnsi(' '.repeat(this.indent) + fullPrefixText + '--' + this[TEXT]).split('\n')) {
for (const line of stripAnsi(fullPrefixText + '--' + this[TEXT]).split('\n')) {
this.lineCount += Math.max(1, Math.ceil(wcwidth(line) / columns));
}
}
Expand Down Expand Up @@ -265,22 +264,15 @@ class Ora {
return this;
}

this.stream.cursorTo(0);

for (let i = 0; i < this.linesToClear; i++) {
if (i > 0) {
this.stream.moveCursor(0, -1);
}

this.stream.clearLine(1);
}

if (this.indent || this.lastIndent !== this.indent) {
this.stream.clearLine();
this.stream.cursorTo(this.indent);
}

this.lastIndent = this.indent;

this.linesToClear = 0;

return this;
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -51,7 +51,6 @@
"@types/node": "^14.14.35",
"ava": "^2.4.0",
"get-stream": "^6.0.0",
"transform-tty": "^1.0.11",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
Expand Down

0 comments on commit b4d879b

Please sign in to comment.