Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the spinner while ora is running? #94

Closed
Bauke opened this issue Jan 21, 2019 · 8 comments
Closed

Change the spinner while ora is running? #94

Bauke opened this issue Jan 21, 2019 · 8 comments
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted

Comments

@Bauke
Copy link

Bauke commented Jan 21, 2019

Issuehunt badges

Hi, didn't see an issue for this while searching. Could it be possible to have some way of changing the current spinner while ora is running? From some testing there's no way to do this without having ora enter a newline. clear() only removes the spinner and not the text so it persists.

jeetiss earned $40.00 by resolving this issue!

@sindresorhus
Copy link
Owner

It's not documented, but I think you can set instance.spinner = 'spinner-name';. We should get that documented and tested. PR welcome for that.

@Bauke
Copy link
Author

Bauke commented Jan 22, 2019

That works but it breaks now and then, I assume because of frameIndex not being set back to 0 so it's trying to find a frame from the new spinner at an index that doesn't exist.

Code:

const ora = require('ora');
const spinners = require('cli-spinners');

const spinArray = [];

for (const spinner in spinners) {
  spinArray.push(spinners[spinner]);
}

const progress = ora('test').start();
progress.color = 'green';

setInterval(() => {
  progress.spinner = spinArray[Math.floor(Math.random() * spinArray.length)];
}, 1000);

peek 2019-01-22 10-45

@sindresorhus
Copy link
Owner

Ok. Thanks for testing.

@sindresorhus
Copy link
Owner

sindresorhus commented Jan 22, 2019

We should rename this.spinner to this._spinner and create a getter/setter (public interface) called spinner, that handles the logic of setting the spinner; the frame index logic and this:

ora/index.js

Lines 26 to 30 in bbc82a4

this.spinner = typeof sp === 'object' ? sp : (process.platform === 'win32' ? cliSpinners.line : (cliSpinners[sp] || cliSpinners.dots)); // eslint-disable-line no-nested-ternary
if (this.spinner.frames === undefined) {
throw new Error('Spinner must define `frames`');
}

@IssueHuntBot
Copy link

@issuehuntfest has funded $40.00 to this issue. See it on IssueHunt

@IssueHuntBot
Copy link

@IssueHunt has cancelled funding for this issue.(Cancelled amount: $40.00) See it on IssueHunt

@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 9, 2019
@IssueHuntBot
Copy link

@IssueHunt has funded $40.00 to this issue.


@issuehunt-oss issuehunt-oss bot added 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt and removed 💵 Funded on Issuehunt This issue has been funded on Issuehunt labels May 9, 2019
@IssueHuntBot
Copy link

@sindresorhus has rewarded $36.00 to @jeetiss. See it on IssueHunt

  • 💰 Total deposit: $40.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $4.00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted
Projects
None yet
Development

No branches or pull requests

3 participants