clui icon indicating copy to clipboard operation
clui copied to clipboard

Spinner with manual ticking

Open Bizarrus opened this issue 7 years ago • 1 comments

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...

Bizarrus avatar Feb 24 '18 19:02 Bizarrus

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...

danjaywing avatar Jun 22 '18 14:06 danjaywing