-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path8-utils.js
More file actions
40 lines (34 loc) · 875 Bytes
/
8-utils.js
File metadata and controls
40 lines (34 loc) · 875 Bytes
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
'use strict';
// Utilities
const write = (s) => process.stdout.write(s);
const read = (callback) => process.stdin.on('data', (chunk) => {
callback(chunk.toString().trim());
});
const clear = () => write('\x1Bc');
const pos = (row, col) => write(`\x1b[${row};${col}H`);
const box = (row, col, height, width) => {
const h = height - 2;
const w = width - 2;
const border = '┌┐─│└┘'.split('');
pos(row, col);
write(border[0] + border[2].repeat(w) + border[1]);
for (let i = 1; i < h; i++) {
pos(row + i, col);
write(border[3] + ' '.repeat(w) + border[3]);
}
pos(row + h, col);
write(border[4] + border[2].repeat(w) + border[5]);
};
// Usage
read((s) => {
write(`\nHello, ${s}!\n`);
process.exit(0);
});
clear();
setTimeout(() => {
write('\n\n');
process.exit(0);
}, 10000);
box(10, 10, 4, 30);
pos(11, 12);
write('Login: ');