summaryrefslogtreecommitdiff
path: root/electron/service/utils/spinner.js
diff options
context:
space:
mode:
Diffstat (limited to 'electron/service/utils/spinner.js')
-rw-r--r--electron/service/utils/spinner.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/electron/service/utils/spinner.js b/electron/service/utils/spinner.js
new file mode 100644
index 00000000..d643a933
--- /dev/null
+++ b/electron/service/utils/spinner.js
@@ -0,0 +1,57 @@
+'use strict'
+
+const ora = require('ora')
+const chalk = require('chalk')
+
+const spinner = ora()
+let lastMsg = null
+let isPaused = false
+
+exports.logWithSpinner = (symbol, msg) => {
+ if (!msg) {
+ msg = symbol
+ symbol = chalk.green('✔')
+ }
+ if (lastMsg) {
+ spinner.stopAndPersist({
+ symbol: lastMsg.symbol,
+ text: lastMsg.text,
+ })
+ }
+ spinner.text = ' ' + msg
+ lastMsg = {
+ symbol: symbol + ' ',
+ text: msg,
+ }
+ spinner.start()
+}
+
+exports.stopSpinner = (persist) => {
+ if (lastMsg && persist !== false) {
+ spinner.stopAndPersist({
+ symbol: lastMsg.symbol,
+ text: lastMsg.text,
+ })
+ } else {
+ spinner.stop()
+ }
+ lastMsg = null
+}
+
+exports.pauseSpinner = () => {
+ if (spinner.isSpinning) {
+ spinner.stop()
+ isPaused = true
+ }
+}
+
+exports.resumeSpinner = () => {
+ if (isPaused) {
+ spinner.start()
+ isPaused = false
+ }
+}
+
+exports.failSpinner = (text) => {
+ spinner.fail(text)
+}