1 module.exports = spinner
3 function spinner(opt) {
5 var str = opt.stream || process.stderr
6 var tty = typeof opt.tty === 'boolean' ? opt.tty : true
7 var string = opt.string || '/-\\|'
8 var ms = typeof opt.interval === 'number' ? opt.interval : 50
10 if (tty && !str.isTTY) return false
11 var CR = str.isTTY ? '\u001b[0G' : '\u000d';
12 var CLEAR = str.isTTY ? '\u001b[2K' : '\u000d \u000d';
15 var sprite = string.split('')
18 var delay = typeof opt.delay === 'number' ? opt.delay : 2
20 var interval = setInterval(function() {
21 if (--delay >= 0) return
22 s = ++s % sprite.length
28 var unref = typeof opt.unref === 'boolean' ? opt.unref : true
29 if (unref && typeof interval.unref === 'function') {
33 var cleanup = typeof opt.cleanup === 'boolean' ? opt.cleanup : true
35 process.on('exit', function() {
42 module.exports.clear = function () {
49 module.exports.clear = function () {};