Skip to content

Instantly share code, notes, and snippets.

@designfrontier
Last active October 10, 2015 02:24
Show Gist options
  • Save designfrontier/3e6a4e1b24e699a730c8 to your computer and use it in GitHub Desktop.
Save designfrontier/3e6a4e1b24e699a730c8 to your computer and use it in GitHub Desktop.
node console spinner (rough)
var arr = [
'\\',
'|',
'/',
'-',
]
, position = 0;
arr = arr.concat(arr, arr, arr, arr, arr, arr);
var spinerval = setInterval(function () {
var spin = arr[position];
if(position > 0) {
spin = '\b' + spin;
}
process.stdout.write(spin);
position++;
if (position === arr.length) {
clearInterval(spinerval);
process.stdout.write('\b' + '');
}
}, 50);
@tuxsudo
Copy link

tuxsudo commented Oct 10, 2015

Can I play too?

function* spinner() {
  yield '\\';
  yield '|';
  yield '/'
  yield '-';
  yield *spinner();
}

let s = spinner();
setInterval( ()=>process.stdout.write("\b" + s.next().value), 30)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment