Lines of Code | 37 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | 'use strict'; |
||
2 | |||
3 | export default class Loading { |
||
4 | constructor(term) { |
||
5 | this.$term = term; |
||
6 | Object.assign(this, { |
||
7 | anim: ['/', '|', '\\', '-'], |
||
8 | prompt: null, |
||
9 | delay: 50, |
||
10 | intervalId: null, |
||
11 | counter: 0 |
||
12 | }); |
||
13 | } |
||
14 | |||
15 | show() { |
||
16 | this.counter++; |
||
17 | this.$term.disable(); |
||
18 | this.prompt = this.$term.get_prompt(); |
||
19 | let i = 0; |
||
20 | this.intervalId = setInterval(() => { |
||
21 | this.$term.set_prompt(this.anim[i++]); |
||
22 | if (i > this.anim.length - 1) { |
||
23 | i = 0; |
||
24 | } |
||
25 | }, this.delay); |
||
26 | } |
||
27 | |||
28 | hide() { |
||
29 | this.counter--; |
||
30 | if (this.counter <= 0) { |
||
31 | clearInterval(this.intervalId); |
||
32 | this.$term.enable(); |
||
33 | this.$term.set_prompt(this.prompt); |
||
34 | this.counter = 0; |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 |