-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest-clear-down.js
42 lines (36 loc) · 916 Bytes
/
test-clear-down.js
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
"use strict";
/**
* @param {number} ms
* @returns {Promise<void>}
*/
function delay(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function goUp() {
const CURSOR_UP = "\x1B[A";
const split = 2;
process.stdout.write(CURSOR_UP.slice(0, split));
await delay(1);
process.stdout.write(CURSOR_UP.slice(split));
}
async function run() {
const CLEAR = "\x1B[2J\x1B[3J\x1B[H";
const CLEAR_DOWN = "\x1B[0J";
const CLEAR_LINE = "\x1B[2K";
process.stdout.write("Apple: in progress\n");
await delay(100);
process.stdout.write("Banana: in progress\n");
await delay(1000);
await goUp();
await goUp();
process.stdout.write(`${CLEAR_LINE}Apple: done\n`);
await delay(1000);
process.stdout.write(`${CLEAR_LINE}Banana: done\n`);
process.stdout.write(`${CLEAR_DOWN}Success!`);
await delay(2000);
process.stdout.write(CLEAR);
await run();
}
run();