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

Spinner with manual ticking #20

Open
Bizarrus opened this issue Feb 24, 2018 · 1 comment
Open

Spinner with manual ticking #20

Bizarrus opened this issue Feb 24, 2018 · 1 comment

Comments

@Bizarrus
Copy link

I wan't to tick manually the spinner.

For sample

var countdown  = new CLI.Spinner('Running...  ', ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷']);
countdown.start();

let's run automatic. But i want to "move" the spinner programatically like

var countdown  = new CLI.Spinner('Running...  ', ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷']);

setInterval(function() {
    countdown.tick();
}, 1000); // each second, the spinner moves...
@danjaywing
Copy link

danjaywing commented Jun 22, 2018

Well the symbols are in the order they are to be animated, so why not just output and replace each symbol every tick?

So something like

var spinnerSymbols = ['⣾','⣽','⣻','⢿','⡿','⣟','⣯','⣷'];
var i = 0;
setInterval(function() {
  process.stdout.clearLine();  // clear line
  process.stdout.cursorTo(0); // move to the start of the line
  process.stdout.write(spinnerSymbols[i]); // write the symbol
    
  // Increase the counter until it reaches the end of the array
  if(i >= (spinnerSymbols.length - 1)) {
    i = 0;
  } else {
    i++;
  }
}, 1000); // each second, the spinner moves...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants