Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
tests/modules/tty/cursor_control.lua
Outdated
| @@ -0,0 +1,134 @@ | |||
| import("core.base.tty") | |||
| import("core.base.scheduler") | |||
tests/modules/tty/cursor_control.lua
Outdated
| io.write("Line 2: Updated content! ✓") | ||
| io.flush() | ||
|
|
||
| -- Move cursor to end | ||
| tty.cursor_move_down(2) |
There was a problem hiding this comment.
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") |
|
|
||
| -- Update Task 1 to Running | ||
| tty.cursor_move_up(3) | ||
| tty.cr() |
There was a problem hiding this comment.
|
|
||
| -- Move to line 3 and update content | ||
| tty.cursor_move_up(3) | ||
| tty.cr() |
xmake/core/base/tty.lua
Outdated
| n = n or 1 | ||
| tty._iowrite(string.format("\x1b[%dA", n)) |
There was a problem hiding this comment.
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
#6805
cursor_control.mov
live_dashboard.mov