-
Notifications
You must be signed in to change notification settings - Fork 6
/
term-utils.mjs
37 lines (31 loc) · 887 Bytes
/
term-utils.mjs
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
export function renderText(x, y, width, height, textLines) {
for (let i = 0; i < height; i++) {
const line = textLines[i] || "";
printAt(x, y + i, padEnd(line.substring(0, width), width, " "));
}
}
function padEnd(stringLike, width, padChar) {
return stringLike.toString() + Array(width - stringLike.length + 1).join(padChar);
}
export function printAt(x, y, value) {
process.stdout.write(`\x1b[${y};${x}f`);
process.stdout.write(value);
}
export function setCursorVisible(visible) {
process.stdout.write(visible ? '\x1b[?25h' : '\x1b[?25l');
}
export function clearScreen() {
write('\x1b[0m');
write('\x1b[2J');
write('\x1bc');
}
export function setMouseButtonTracking(on) {
if (on) {
write('\x1b[?1000h');
} else {
write('\x1b[?1000l');
}
}
function write(value) {
process.stdout.write(value);
}