Skip to content

Commit 6e16fca

Browse files
committed
add spinner to CLI
1 parent 2106f5f commit 6e16fca

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bin/index.js

100644100755
+6-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
const word = require('../index')
44

5-
function writeToConsole() {
5+
function writeToConsole(output) {
66
process.stdout.clearLine();
77
process.stdout.cursorTo(0);
8-
process.stdout.write(word());
8+
process.stdout.write(output);
99
}
1010

1111
console.log("Choosing a word for you...");
1212

1313
(async function demo() {
1414
for (let i = 0; i < 500; i++) {
1515
await new Promise(resolve => setTimeout(resolve, 5));
16-
writeToConsole();
16+
let spinner = ["/ ", "—", "\\ ", "| "]
17+
output = spinner[i % 4] + word()
18+
writeToConsole(output);
1719
}
18-
})().then( () => console.log('') );
20+
})().then( () => writeToConsole("=> " + word() + "\n") );
1921

0 commit comments

Comments
 (0)