Skip to content

Commit

Permalink
Fix cursor position jump in stopAll method
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcarpanelli committed May 22, 2019
1 parent 30727c9 commit 7db298b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Spinners {
};
this.spinners = {};
this.isCursorHidden = false;
this.linesLength = [];
this.currentInterval = null;
if (this.options.preventLineBreaks) preventLineBreaks();
}
Expand Down Expand Up @@ -107,10 +108,10 @@ class Spinners {
setStream(frame = '') {
let line;
let stream = '';
const linesLength = [];
this.linesLength = [];
Object.values(this.spinners).map(({ text, status, color, spinnerColor, successColor, failColor }) => {
text = breakText(text);
linesLength.push(...getLinesLength(text));
this.linesLength.push(...getLinesLength(text));
if (status === 'spinning') {
line = `${chalk[spinnerColor](frame)} ${chalk[color](text)}`;
} else if (status === 'success') {
Expand All @@ -123,16 +124,16 @@ class Spinners {
stream += `${line}\n`;
});

cleanStream(linesLength);
writeStream(stream, linesLength);
cleanStream(this.linesLength);
writeStream(stream, this.linesLength);
}

checkIfActiveSpinners() {
const { interval } = this.options.spinner;
if (!this.hasActiveSpinners()) {
clearInterval(this.currentInterval);
this.setStream();
readline.moveCursor(process.stderr, 0, Object.keys(this.spinners).length);
readline.moveCursor(process.stderr, 0, this.linesLength.length);
this.spinners = {};
cliCursor.show();
this.isCursorHidden = false;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spinnies",
"version": "0.1.2",
"version": "0.1.3",
"description": "Create and manage multiple spinners in command-line interface programs",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 7db298b

Please sign in to comment.