fix: fixed tui log rendering and scroll behavior#264
Conversation
Summary of ChangesHello, 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 addresses and resolves issues related to log rendering and scrolling within the TUI. By leveraging an unstable Highlights
Changelog
Activity
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 refactors the TUI log rendering and scrolling behavior, notably by changing the semantics of log_scroll and leveraging an unstable ratatui feature for better line wrapping calculations. It also introduces a utility to clean log lines. The changes are generally well-implemented, but I've identified a regression in the search result sorting logic that needs to be addressed. I've also included a suggestion to optimize the new log cleaning function for better performance.
Greptile SummaryThis PR refactors the TUI log rendering to fix scroll behavior by changing Major changes:
Critical issues found:
Confidence Score: 1/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start[Log Rendering] --> CheckFollow{log_follow enabled?}
CheckFollow -->|Yes| SetToEnd[Set log_scroll = log_content.len]
CheckFollow -->|No| CheckScroll[Use current log_scroll]
SetToEnd --> CalcWindow[Calculate viewport window]
CheckScroll --> CalcWindow
CalcWindow --> Skip[log_skip = log_scroll - LOG_VIEWPORT_MAX_LINES]
Skip --> Take[log_take = min log_scroll, LOG_VIEWPORT_MAX_LINES]
Take --> GetLines[Get lines from buffer: skip log_skip, take log_take]
GetLines --> Clean[Clean log lines: remove tabs, ANSI codes]
Clean --> Highlight[Apply syntax highlighting and search matches]
Highlight --> Pad{lines < LOG_VIEWPORT_MAX_LINES?}
Pad -->|Yes| AddPadding[Add empty lines to reach LOG_VIEWPORT_MAX_LINES]
Pad -->|No| CreateParagraph[Create Paragraph widget]
AddPadding --> CreateParagraph
CreateParagraph --> CountLines[Calculate line_count with text wrapping]
CountLines --> CalcScroll[scroll_offset = line_count - area.height ⚠️ underflow risk]
CalcScroll --> Render[Render widget with scroll offset]
Render --> End[Display logs]
Last reviewed commit: ea29b5a |
Additional Comments (1)
|
|
log_scroll should have a minimum of 1, because otherwise it's possible for the top of the viewport to not be shown either for the same reason why the bottom was hidden in the previous implementation. |
The scroll behavior is actually not as simple to fix as I thought. The main observation is that there really isn't any good way to retrieve the number of lines the log renderer will take after wrapping. There is a feature within ratatui to enable getting number of lines that will be rendered, but it is unstable for now. Although the log viewer works a lot better with it enabled.
This PR changes the meaning of
log_scroll. In the past,log_scrollrepresents the beginning of the log buffer that will be rendered to the screen, but text wrapping made it such that lines can be hidden below the display buffer. In this PR,log_scrollrepresents the line number of the last displayed line in the buffer instead, while usingParagraph::line_count(the unstable feature) to scroll to the bottom instead.This PR also adds a function to clean the logs of the tab character and the clear screen ansi code. I expect more to be added in the future, but these are the two main ones that are breaking the log panel in my testing.