-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspinner.mjs
More file actions
executable file
·48 lines (44 loc) · 1.45 KB
/
spinner.mjs
File metadata and controls
executable file
·48 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env nodejsscript
/*
You can create quick spinner animation using `css-in-console`:
```js
const css= echo.css`
.spin { list-style: --terminal-spin; }
`;
```
… and
```js
echo.use("-R", "%c", css.spin);
```
*/
/* jshint esversion: 8,-W097, -W040, node: true, expr: true, undef: true *//* global echo, $, cyclicLoop */
const css= echo.css`
.spin { color: lightmagenta; list-style-type: --terminal-spin; }
@counter-style custom-spin{
system: extends --terminal-spin;
symbols: "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z";
}
.spinLetters { list-style-type: custom-spin; }
.info { color: lightblue; }
.success { color: lightgreen; }
.success:before { content: '✓ '; }
`;
longTask(spinner("Long task running…"))
.then(function(spinEnd){
spinEnd("%cFirst long task ended successfully.", css.success);
return longTask(spinner("Second long task running…", { animation: css.spinLetters }));
})
.then(function(spinEnd){
spinEnd("%cSecond long task ended successfully.", css.success);
$.exit(0);
});
import { setTimeout } from "node:timers/promises";
function longTask(out){ return setTimeout(15*750, out); }
function spinner(message= "Waiting", { interval= 750, animation= "" }= {}){
const echoSpin= ()=> echo.use("-R", `%c%c${message}`, css.spin+animation, css.info);
const id= setInterval(echoSpin, interval);
return function(...message){
clearInterval(id);
echo(...message);
};
}