-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathansi.ts
33 lines (26 loc) · 918 Bytes
/
ansi.ts
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
const ESC = "\x1b";
export const textEncoder = new TextEncoder();
export const ansi = (str: string) => {
return textEncoder.encode(`${ESC}${str}`);
};
export const previousCurrentLine = () => {
Deno.stdout.writeSync(ansi("[1A")); // delete entire current line")
Deno.stdout.writeSync(ansi("[2K")); // delete entire current line")
Deno.stdout.writeSync(ansi("[0G")); // move cursor to head of line
};
export const makeInvisibleCursor = () => {
Deno.stdout.writeSync(ansi("[?25l"));
};
export const makeVisibleCursor = () => {
Deno.stdout.writeSync(ansi("[?25h"));
};
export const eraseCurrentLine = () => {
Deno.stdout.writeSync(ansi("[2K")); // delete entire current line")
Deno.stdout.writeSync(ansi("[0G")); // move cursor to head of line
};
export const saveCursor = () => {
Deno.stdout.writeSync(ansi("[s"));
};
export const restoreCursor = () => {
Deno.stdout.writeSync(ansi("[u"));
};