-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tty_sync.ts
120 lines (97 loc) · 2.68 KB
/
tty_sync.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { encode } from "./util.ts";
import {
CLEAR_DOWN,
CLEAR_LEFT,
CLEAR_LINE,
CLEAR_RIGHT,
CLEAR_SCREEN,
CLEAR_UP,
DOWN,
ESC,
HIDE,
HOME,
LEFT,
NEXT_LINE,
POSITION,
PREV_LINE,
RESTORE,
RIGHT,
SCROLL_DOWN,
SCROLL_UP,
SHOW,
type SyncStream,
UP,
} from "./mod.ts";
export function writeSync(str: string, writer: SyncStream): void {
writer.writeSync(encode(str));
}
export function restoreSync(writer: SyncStream = Deno.stdout): void {
writeSync(RESTORE, writer);
}
export function cursorSync(
action: string,
writer: SyncStream = Deno.stdout,
): void {
writeSync(ESC + action, writer);
}
export function positionSync(writer: SyncStream = Deno.stdout): void {
cursorSync(POSITION, writer);
}
export function hideCursorSync(writer: SyncStream = Deno.stdout): void {
cursorSync(HIDE, writer);
}
export function showCursorSync(writer: SyncStream = Deno.stdout): void {
cursorSync(SHOW, writer);
}
export function scrollUpSync(writer: SyncStream = Deno.stdout): void {
cursorSync(SCROLL_UP, writer);
}
export function scrollDownSync(writer: SyncStream = Deno.stdout): void {
cursorSync(SCROLL_DOWN, writer);
}
export function clearUpSync(writer: SyncStream = Deno.stdout): void {
cursorSync(CLEAR_UP, writer);
}
export function clearDownSync(writer: SyncStream = Deno.stdout): void {
cursorSync(CLEAR_DOWN, writer);
}
export function clearLeftSync(writer: SyncStream = Deno.stdout): void {
cursorSync(CLEAR_LEFT, writer);
}
export function clearRightSync(writer: SyncStream = Deno.stdout): void {
cursorSync(CLEAR_RIGHT, writer);
}
export function clearLineSync(writer: SyncStream = Deno.stdout): void {
cursorSync(CLEAR_LINE, writer);
}
export function clearScreenSync(writer: SyncStream = Deno.stdout): void {
cursorSync(CLEAR_SCREEN, writer);
}
export function nextLineSync(writer: SyncStream = Deno.stdout): void {
cursorSync(NEXT_LINE, writer);
}
export function prevLineSync(writer: SyncStream = Deno.stdout): void {
cursorSync(PREV_LINE, writer);
}
export function goHomeSync(writer: SyncStream = Deno.stdout): void {
cursorSync(HOME, writer);
}
export function goUpSync(y = 1, writer: SyncStream = Deno.stdout): void {
cursorSync(y + UP, writer);
}
export function goDownSync(y = 1, writer: SyncStream = Deno.stdout): void {
cursorSync(y + DOWN, writer);
}
export function goLeftSync(x = 1, writer: SyncStream = Deno.stdout): void {
cursorSync(x + LEFT, writer);
}
export function goRightSync(x = 1, writer: SyncStream = Deno.stdout): void {
cursorSync(`${x}${RIGHT}`, writer);
}
export function goToSync(
x: number,
y: number,
writer: SyncStream = Deno.stdout,
): void {
writeSync(ESC + y + ";" + x + HOME, writer);
}