diff options
| author | ruki <[email protected]> | 2025-10-27 22:56:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-10-27 22:56:18 +0800 |
| commit | 5b49833ed61286d6c75f0005c4e96092380946eb (patch) | |
| tree | 918ef38c29acab827872fd4c123e6d983978335a /tests/modules/tty/quick_example.lua | |
| parent | 1dc87c3ed7069e7d0ab21b107ef470e3c793ca9e (diff) | |
improve tty test
Diffstat (limited to 'tests/modules/tty/quick_example.lua')
| -rw-r--r-- | tests/modules/tty/quick_example.lua | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/tests/modules/tty/quick_example.lua b/tests/modules/tty/quick_example.lua index 6b68394f7..794a79d58 100644 --- a/tests/modules/tty/quick_example.lua +++ b/tests/modules/tty/quick_example.lua @@ -35,25 +35,26 @@ function example2_update_previous_line() return end - print("Building project...") - print("Status: Starting...") + io.write("Building project...\n") + io.write("Status: Starting...\n") + io.flush() os.sleep(1000) -- Go back and update the status line tty.cursor_move_up(1) + tty.cr() tty.erase_line() - io.write("Status: Compiling files...") + io.write("Status: Compiling files...\n") io.flush() - print("") -- Move to next line os.sleep(1000) tty.cursor_move_up(1) + tty.cr() tty.erase_line() - io.write("Status: Done! ✓") + io.write("Status: Done! ✓\n") io.flush() - print("") end function example3_multi_line_update() @@ -65,59 +66,55 @@ function example3_multi_line_update() end -- Create a simple status board - print("Task 1: Waiting...") - print("Task 2: Waiting...") - print("Task 3: Waiting...") + io.write("Task 1: Waiting...\n") + io.write("Task 2: Waiting...\n") + io.write("Task 3: Waiting...\n") + io.flush() tty.cursor_hide() - -- Update Task 1 - tty.cursor_save() + -- Update Task 1 to Running tty.cursor_move_up(3) + tty.cr() tty.erase_line() - io.write("Task 1: Running... ") + io.write("Task 1: Running... \n") io.flush() - tty.cursor_restore() os.sleep(500) - tty.cursor_save() - tty.cursor_move_up(3) + -- Update Task 1 to Done + tty.cursor_move_up(1) + tty.cr() tty.erase_line() - io.write("Task 1: Done ✓") + io.write("Task 1: Done ✓\n") io.flush() - tty.cursor_restore() - -- Update Task 2 - tty.cursor_save() - tty.cursor_move_up(2) + -- Update Task 2 to Running + tty.cr() tty.erase_line() - io.write("Task 2: Running... ") + io.write("Task 2: Running... \n") io.flush() - tty.cursor_restore() os.sleep(500) - tty.cursor_save() - tty.cursor_move_up(2) + -- Update Task 2 to Done + tty.cursor_move_up(1) + tty.cr() tty.erase_line() - io.write("Task 2: Done ✓") + io.write("Task 2: Done ✓\n") io.flush() - tty.cursor_restore() - -- Update Task 3 - tty.cursor_save() - tty.cursor_move_up(1) + -- Update Task 3 to Running + tty.cr() tty.erase_line() - io.write("Task 3: Running... ") + io.write("Task 3: Running... \n") io.flush() - tty.cursor_restore() os.sleep(500) - tty.cursor_save() + -- Update Task 3 to Done tty.cursor_move_up(1) + tty.cr() tty.erase_line() - io.write("Task 3: Done ✓") + io.write("Task 3: Done ✓\n") io.flush() - tty.cursor_restore() tty.cursor_show() end |
