UNPKG

1.31 kBJavaScriptView Raw
1var spinners = {
2 Box1: '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏',
3 Box2: '⠋⠙⠚⠞⠖⠦⠴⠲⠳⠓',
4 Box3: '⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆',
5 Box4: '⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋',
6 Box5: '⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁',
7 Box6: '⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈',
8 Box7: '⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈',
9 Spin1: '|/-\\',
10 Spin2: '◴◷◶◵',
11 Spin3: '◰◳◲◱',
12 Spin4: '◐◓◑◒',
13 Spin5: '▉▊▋▌▍▎▏▎▍▌▋▊▉',
14 Spin6: '▌▄▐▀',
15 Spin7: '╫╪',
16 Spin8: '■□▪▫',
17 Spin9: '←↑→↓'
18}
19
20function Spin (type, words) {
21 this.pos = 0
22 this.words = words ? words + ' ' : ''
23 this.type = type || 'Spin1'
24}
25
26Spin.prototype = {
27 counstructor: Spin,
28 start: function () {
29 var spinner = spinners[this.type]
30 this.loop = setInterval(function () {
31 process.stdout.write('\r' + this.words + spinner.charAt(this.pos))
32 if (this.pos === spinner.length - 1) {
33 this.pos = 0
34 } else {
35 this.pos++
36 }
37 }.bind(this), 100)
38 },
39 stop: function () {
40 process.stdout.write('\r')
41 clearInterval(this.loop)
42 }
43}
44
45module.exports = Spin