UNPKG

845 BJavaScriptView Raw
1const ora = require('ora');
2
3const spinner = ora();
4let lastMsg = null;
5
6const {
7 cyan,
8} = require('./colorStr');
9
10const {
11 success,
12} = require('./icons');
13
14module.exports = {
15 logWithSpinner(symbol, msg) {
16 if (!msg) {
17 msg = symbol;
18 symbol = cyan(success);
19 }
20 if (lastMsg) {
21 spinner.stopAndPersist({
22 symbol: lastMsg.symbol,
23 text: lastMsg.text,
24 });
25 }
26 spinner.text = `${msg}`;
27 lastMsg = {
28 symbol: ` ${symbol}`,
29 text: msg,
30 };
31 spinner.start();
32 },
33
34 stopSpinner(persist) {
35 if (lastMsg && persist !== false) {
36 spinner.stopAndPersist({
37 symbol: lastMsg.symbol,
38 text: persist,
39 });
40 } else {
41 spinner.stop();
42 }
43 lastMsg = null;
44 },
45
46 pauseSpinner: () => spinner.stop(),
47
48 resumeSpinner: () => spinner.start(),
49};