summaryrefslogtreecommitdiff
path: root/tests/modules/tty/cursor_control.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-10-27 23:23:40 +0800
committerruki <[email protected]>2025-10-27 23:23:40 +0800
commitd4d2990f3f5d017542338acc1b753f669d4ec9a2 (patch)
tree02dc6f90f6e75d7ea1317078c7c8ce540e5f752d /tests/modules/tty/cursor_control.lua
parent06dd715e91d3fed3b8101801eceda228c3ed4877 (diff)
fix whitespaces
Diffstat (limited to 'tests/modules/tty/cursor_control.lua')
-rw-r--r--tests/modules/tty/cursor_control.lua44
1 files changed, 22 insertions, 22 deletions
diff --git a/tests/modules/tty/cursor_control.lua b/tests/modules/tty/cursor_control.lua
index 4502617eb..1dbb650bf 100644
--- a/tests/modules/tty/cursor_control.lua
+++ b/tests/modules/tty/cursor_control.lua
@@ -7,7 +7,7 @@ function _progress_bar_inline(label, progress)
local bar_width = 40
local filled = math.floor(progress * bar_width)
local bar = string.rep("█", filled) .. string.rep("░", bar_width - filled)
-
+
-- Clear the line and output content
tty.cr()
tty.erase_line()
@@ -25,51 +25,51 @@ function main()
print("=== TTY Cursor Control Demo ===")
print("This demo shows partial screen refresh using cursor positioning")
print("")
-
+
-- Hide cursor for smoother display
tty.cursor_hide()
-
+
print("\nDemo 1: Multiple Progress Bars (Parallel Updates)")
print("------------------------------------------------")
-
+
-- Reserve lines for progress bars
io.write("Task 1: Downloading\n")
io.write("Task 2: Compiling \n")
io.write("Task 3: Linking \n")
io.flush()
-
+
-- Simulate three parallel task progress bars
for step = 1, 100 do
-- Move to Task 1 line (3 lines up from current position)
tty.cursor_move_up(3)
-
+
-- Update Task 1 progress
local progress1 = step / 100
_progress_bar_inline("Task 1: Downloading", progress1)
io.write("\n")
-
+
-- Update Task 2 progress (starts later, progresses faster)
local progress2 = math.max(0, math.min(1.0, (step - 10) / 80))
_progress_bar_inline("Task 2: Compiling ", progress2)
io.write("\n")
-
+
-- Update Task 3 progress (starts even later)
local progress3 = math.max(0, math.min(1.0, (step - 30) / 60))
_progress_bar_inline("Task 3: Linking ", progress3)
io.write("\n")
io.flush()
-
+
os.sleep(30) -- 30ms delay
end
-
+
print("\n\nDemo 2: Dynamic Status Updates")
print("--------------------------------")
-
+
-- Print initial status and counter
io.write("Status: Waiting...\n")
io.write("Counter: 0\n")
io.flush()
-
+
local statuses = {
"Initializing...",
"Loading configuration...",
@@ -79,47 +79,47 @@ function main()
"Linking executable...",
"Done!"
}
-
+
for i, status in ipairs(statuses) do
-- Move to status line (2 lines up)
tty.cursor_move_up(2)
-
+
-- Update status line
tty.cr()
tty.erase_line()
io.write(string.format("Status: %s", status))
io.write("\n")
-
+
-- Update counter line
tty.cr()
tty.erase_line()
io.write(string.format("Counter: %d", i * 100))
io.write("\n")
io.flush()
-
+
os.sleep(500)
end
-
+
-- Restore cursor visibility
tty.cursor_show()
-
+
print("\n\nDemo 3: Erase and Update Specific Line")
print("----------------------------------------")
-
+
io.write("Line 1: This line will stay\n")
io.write("Line 2: This line will be updated...\n")
io.write("Line 3: This line will stay too\n")
io.flush()
-
+
os.sleep(1000)
-
+
-- Update only the middle line (2 lines up)
tty.cursor_move_up(2)
tty.cr()
tty.erase_line()
io.write("Line 2: Updated content! ✓\n")
io.flush()
-
+
-- Move cursor to end
tty.cursor_move_down(1)
print("\n\nAll demos completed!")