Skip to content

Improve tty#6970

Merged
waruqi merged 5 commits intodevfrom
tty
Oct 27, 2025
Merged

Improve tty#6970
waruqi merged 5 commits intodevfrom
tty

Conversation

@waruqi
Copy link
Member

@waruqi waruqi commented Oct 27, 2025

#6805

cursor_control.mov
live_dashboard.mov

@waruqi waruqi added this to the v3.0.5 milestone Oct 27, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @waruqi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the core.base.tty module by integrating a suite of new cursor control and screen manipulation functions. These additions empower developers to build more interactive and dynamic command-line interfaces, moving beyond simple linear output to enable features like real-time progress updates, live dashboards, and selective screen refreshes. The changes are supported by a collection of new test and example files that showcase the practical application and validate the functionality of these new TTY capabilities.

Highlights

  • New TTY Cursor Control Functions: Introduced a comprehensive set of functions for cursor manipulation within the core.base.tty module, including absolute and relative cursor movement, and cursor visibility control.
  • Enhanced Terminal UI Capabilities: The new functions enable the creation of dynamic terminal user interfaces, such as real-time progress bars, live dashboards, and partial screen updates, significantly improving interactive console applications.
  • Extensive Demos and Tests: Added four new Lua files (cursor_control.lua, live_dashboard.lua, quick_example.lua, test.lua) under tests/modules/tty to demonstrate and thoroughly test the new cursor control and screen manipulation features.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable set of TTY cursor control functions to core.base.tty, along with comprehensive demonstration and test files. The new API is well-structured and enables advanced terminal UI features. My review focuses on improving the robustness of the new API and correcting a few minor logical issues and redundancies in the accompanying example files. The most notable issue is a cursor position calculation error in the live_dashboard.lua demo. Once these points are addressed, this will be an excellent enhancement.

local function update_task_line(task_index, icon, name, progress)
-- Move to the task line (from current cursor position)
-- We need to go up: log_count lines + 1 separator line + (5 - task_index) task lines
local lines_up = log_count + 1 + (5 - task_index + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The calculation for lines_up is off by one, and the explanatory comment on the preceding line is also incorrect. Given the layout created by io.write("\nRecent logs:\n"), there are two lines (a blank line and the 'Recent logs:' line) between the last task and the initial cursor position. The formula should be log_count + 8 - task_index to correctly position the cursor. For example, to update the first task (task_index = 1) with no logs (log_count = 0), the cursor needs to move up 7 lines, but the current formula calculates 6.

        local lines_up = log_count + 8 - task_index

@@ -0,0 +1,134 @@
import("core.base.tty")
import("core.base.scheduler")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The core.base.scheduler module is imported but never used in this file. It's good practice to remove unused imports to keep the code clean.

Comment on lines +121 to +125
io.write("Line 2: Updated content! ✓")
io.flush()

-- Move cursor to end
tty.cursor_move_down(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The io.write call on line 121 is missing a newline character (\n), which causes incorrect cursor positioning for subsequent print calls. To fix this, add a newline to the io.write and adjust the following tty.cursor_move_down to move the cursor to the correct final position.

    io.write("Line 2: Updated content! ✓\n")
    io.flush()
    
    -- Move cursor to end
    tty.cursor_move_down(1)

print("\n\nAll demos completed!")
print("\nKey features demonstrated:")
print(" - cursor_move_up/down/left/right: Move cursor relatively")
print(" - cursor_save/restore: Save and restore cursor position")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The summary of demonstrated features mentions cursor_save/restore, but these functions are not actually used in this demo file. This could be confusing. Please remove this line to accurately reflect the demo's content.


-- Update Task 1 to Running
tty.cursor_move_up(3)
tty.cr()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This call to tty.cr() is redundant. After tty.cursor_move_up(3), the cursor is already at the beginning of the line. This applies to all other tty.cr() calls in the example3_multi_line_update function as well (lines 86, 92, 100, 106, 114). You can safely remove them to simplify the code.


-- Move to line 3 and update content
tty.cursor_move_up(3)
tty.cr()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This tty.cr() call is redundant. The tty.cursor_move_up(3) call on the previous line already places the cursor at the beginning of the target line.

Comment on lines +152 to +153
n = n or 1
tty._iowrite(string.format("\x1b[%dA", n))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this works, it's slightly more efficient to avoid sending an escape code if n is 0. Also, the behavior for negative values is undefined. It would be more robust to only process positive values for n.

This same logic applies to cursor_move_down, cursor_move_right, and cursor_move_left.

    n = n or 1
    if n > 0 then
        tty._iowrite(string.format("\x1b[%dA", n))
    end

@waruqi waruqi mentioned this pull request Oct 27, 2025
@waruqi waruqi merged commit 06dd715 into dev Oct 27, 2025
44 checks passed
@waruqi waruqi deleted the tty branch October 27, 2025 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant