blob: 3dbf6023114ef6213a8de13f5fec31b33359fa19 (
plain)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
import("core.base.tty")
function test_cursor_move()
if not tty.has_vtansi() then
print("Terminal does not support ANSI control codes, skipping test")
return
end
print("\n=== Test: cursor_move ===")
io.write("Line 1\n")
io.write("Line 2\n")
io.write("Line 3\n")
io.write("Line 4\n")
io.write("Line 5\n")
io.flush()
os.sleep(1000)
-- Move to line 3 and update content
tty.cursor_move_up(3)
tty.cr()
tty.erase_line()
io.write("Line 3 - UPDATED!\n")
io.flush()
-- Move cursor back to end
tty.cursor_move_down(2)
print("\n✓ cursor_move_up test passed")
end
function test_cursor_move_directions()
if not tty.has_vtansi() then
return
end
print("\n=== Test: cursor movement directions ===")
-- Create a small coordinate system
for i = 1, 5 do
io.write(string.rep(" ", 60) .. "\n")
end
io.flush()
-- Move to starting position
tty.cursor_move_up(5)
tty.cursor_move_right(10)
io.write("START")
io.flush()
os.sleep(500)
-- Move right
tty.cursor_move_right(10)
io.write("RIGHT")
io.flush()
os.sleep(500)
-- Move down
tty.cursor_move_down(2)
io.write("DOWN")
io.flush()
os.sleep(500)
-- Move left
tty.cursor_move_left(5)
io.write("LEFT")
io.flush()
os.sleep(500)
-- Move up
tty.cursor_move_up(1)
io.write("UP")
io.flush()
-- Move to end
tty.cursor_move_down(3)
io.write("\n")
io.flush()
print("✓ cursor movement directions test passed")
end
function test_cursor_hide_show()
if not tty.has_vtansi() then
return
end
print("\n=== Test: cursor hide/show ===")
print("Cursor is visible now...")
os.sleep(1000)
tty.cursor_hide()
print("Cursor is hidden now (you shouldn't see it blinking)...")
os.sleep(2000)
tty.cursor_show()
print("Cursor is visible again!")
print("✓ cursor hide/show test passed")
end
function test_erase_operations()
if not tty.has_vtansi() then
return
end
print("\n=== Test: erase operations ===")
-- Test erase_line_to_end
io.write("This is a long line that will be partially erased")
io.flush()
os.sleep(1000)
tty.cursor_move_left(30)
tty.erase_line_to_end()
io.write("<- erased to end\n")
io.flush()
os.sleep(1000)
-- Test full line erase
io.write("This entire line will be erased")
io.flush()
os.sleep(1000)
tty.cr()
tty.erase_line()
io.write("Replaced!\n")
io.flush()
print("✓ erase operations test passed")
end
function test_partial_screen_update()
if not tty.has_vtansi() then
return
end
print("\n=== Test: partial screen update ===")
-- Create a table
io.write("┌────────────────────────────────┐\n")
io.write("│ Task │ Status │\n")
io.write("├────────────────────────────────┤\n")
io.write("│ Compile │ Pending... │\n")
io.write("│ Link │ Pending... │\n")
io.write("│ Package │ Pending... │\n")
io.write("└────────────────────────────────┘\n")
io.flush()
os.sleep(1000)
tty.cursor_hide()
-- Update first task status
tty.cursor_move_up(4)
tty.cursor_move_to_col(32)
tty.erase_line_to_end()
io.write("│ Running... │\n")
io.flush()
os.sleep(800)
tty.cursor_move_up(1)
tty.cursor_move_to_col(32)
tty.erase_line_to_end()
io.write("│ Done! ✓ │\n")
io.flush()
os.sleep(500)
-- Update second task status
tty.cursor_move_to_col(32)
tty.erase_line_to_end()
io.write("│ Running... │\n")
io.flush()
os.sleep(800)
tty.cursor_move_up(1)
tty.cursor_move_to_col(32)
tty.erase_line_to_end()
io.write("│ Done! ✓ │\n")
io.flush()
os.sleep(500)
-- Update third task status
tty.cursor_move_to_col(32)
tty.erase_line_to_end()
io.write("│ Running... │\n")
io.flush()
os.sleep(800)
tty.cursor_move_up(1)
tty.cursor_move_to_col(32)
tty.erase_line_to_end()
io.write("│ Done! ✓ │\n")
io.flush()
tty.cursor_show()
tty.cursor_move_down(1)
print("\n✓ partial screen update test passed")
end
function main(...)
-- Run all tests
test_cursor_move()
test_cursor_move_directions()
test_cursor_hide_show()
test_erase_operations()
test_partial_screen_update()
print("\n" .. string.rep("=", 50))
print("All TTY cursor control tests completed!")
print(string.rep("=", 50))
end
|