-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtty_async.ts
160 lines (137 loc) · 3.07 KB
/
tty_async.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { encode } from "./util.ts";
import {
type AsyncStream,
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,
UP,
} from "./mod.ts";
export async function write(str: string, writer: AsyncStream): Promise<void> {
await writer.write(encode(str));
}
export async function restore(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await write(RESTORE, writer);
}
export async function cursor(
action: string,
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await write(ESC + action, writer);
}
export async function position(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(POSITION, writer);
}
export async function hideCursor(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(HIDE, writer);
}
export async function showCursor(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(SHOW, writer);
}
export async function scrollUp(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(SCROLL_UP, writer);
}
export async function scrollDown(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(SCROLL_DOWN, writer);
}
export async function clearUp(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_UP, writer);
}
export async function clearDown(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_DOWN, writer);
}
export async function clearLeft(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_LEFT, writer);
}
export async function clearRight(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_RIGHT, writer);
}
export async function clearLine(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_LINE, writer);
}
export async function clearScreen(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(CLEAR_SCREEN, writer);
}
export async function nextLine(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(NEXT_LINE, writer);
}
export async function prevLine(
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(PREV_LINE, writer);
}
export async function goHome(writer: AsyncStream = Deno.stdout): Promise<void> {
await cursor(HOME, writer);
}
export async function goUp(
y = 1,
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(y + UP, writer);
}
export async function goDown(
y = 1,
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(y + DOWN, writer);
}
export async function goLeft(
x = 1,
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(x + LEFT, writer);
}
export async function goRight(
x = 1,
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await cursor(x + RIGHT, writer);
}
export async function goTo(
x: number,
y: number,
writer: AsyncStream = Deno.stdout,
): Promise<void> {
await write(ESC + y + ";" + x + HOME, writer);
}