Repository navigation
Fix terminal loader flicker and layout shifts - #19
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughTerminal rendering now reserves transient space, responds to resize events, truncates ANSI-colored lines to terminal width, uses synchronized updates, and rewrites loader and status output with reduced terminal wrapping. ChangesTerminal rendering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant event_read as event::read
participant run_loop
participant render
participant Terminal
run_loop->>event_read: read terminal event
event_read-->>run_loop: return resize event
run_loop->>render: re-render frame
render->>Terminal: queue synchronized drawing and clearing
render->>Terminal: flush frame
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/commands/list.rs (1)
184-202: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winRedundant "extra lines" clearing block.
Lines 184-195 explicitly clear/print
extraold lines and move back up, but the unconditionalClear(FromCursorDown)added right after (197-202) already erases everything below the cursor's current position — which is the exact same position the 184-195 block ends at either way. The block is now dead weight (extra terminal writes that get immediately overwritten).♻️ Proposed simplification
- if frame.len() < self.last_rendered_lines { - let extra = self.last_rendered_lines - frame.len(); - for _ in 0..extra { - crossterm::queue!( - stdout, - terminal::Clear(ClearType::CurrentLine), - crossterm::style::Print("\r\n") - ) - .ok(); - } - crossterm::queue!(stdout, cursor::MoveUp(extra as u16)).ok(); - } - crossterm::queue!( stdout, terminal::Clear(ClearType::FromCursorDown), EndSynchronizedUpdate ) .ok();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/list.rs` around lines 184 - 202, Remove the conditional extra-lines clearing loop and cursor move-up from the rendering flow around frame and last_rendered_lines. Keep the unconditional Clear(ClearType::FromCursorDown) and EndSynchronizedUpdate queue intact so stale content below the current cursor is cleared without redundant terminal writes.
🧹 Nitpick comments (1)
src/tui.rs (1)
12-28: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider
unicode-widthinstead of a hand-rolled table.The custom Unicode range table is a reasonable approximation but misses some ambiguous/ zero-width codepoints (e.g. variation selectors like U+FE0F fall through to the default width-1 case) and needs manual upkeep as new emoji/CJK ranges are assigned. A maintained crate like
unicode-widthis the idiomatic choice here and would reduce this maintenance burden.♻️ Illustrative refactor
+use unicode_width::UnicodeWidthChar; + fn character_width(character: char) -> usize { - match character as u32 { - 0x0000..=0x001f | 0x007f..=0x009f | 0x0300..=0x036f => 0, - 0x1100..=0x115f - | 0x2329..=0x232a - | 0x2e80..=0xa4cf - | 0xac00..=0xd7a3 - | 0xf900..=0xfaff - | 0xfe10..=0xfe19 - | 0xfe30..=0xfe6f - | 0xff00..=0xff60 - | 0xffe0..=0xffe6 - | 0x1f300..=0x1faff - | 0x20000..=0x3fffd => 2, - _ => 1, - } + UnicodeWidthChar::width(character).unwrap_or(0) }Please confirm the crate's behavior matches expectations for control/zero-width characters before adopting.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tui.rs` around lines 12 - 28, Replace the hand-rolled range matching in character_width with the maintained unicode-width crate’s character-width API, adding the dependency and importing the required trait or function. Confirm and preserve width 0 for control, combining, and variation-selector characters, width 2 for wide CJK/emoji characters, and the existing fallback behavior for ordinary characters.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tui.rs`:
- Around line 178-200: Recompute the terminal width inside each iteration of the
loader loop before calling truncate_rendered_line, rather than capturing
max_width once before the loop. Update the loop around handle, shown_at, and
truncate_rendered_line so every rendered frame uses the current terminal width
during resizes.
---
Outside diff comments:
In `@src/commands/list.rs`:
- Around line 184-202: Remove the conditional extra-lines clearing loop and
cursor move-up from the rendering flow around frame and last_rendered_lines.
Keep the unconditional Clear(ClearType::FromCursorDown) and
EndSynchronizedUpdate queue intact so stale content below the current cursor is
cleared without redundant terminal writes.
---
Nitpick comments:
In `@src/tui.rs`:
- Around line 12-28: Replace the hand-rolled range matching in character_width
with the maintained unicode-width crate’s character-width API, adding the
dependency and importing the required trait or function. Confirm and preserve
width 0 for control, combining, and variation-selector characters, width 2 for
wide CJK/emoji characters, and the existing fallback behavior for ordinary
characters.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c2a388bc-8044-4bb8-a517-99b3285a5426
📒 Files selected for processing (2)
src/commands/list.rssrc/tui.rs
Summary by CodeRabbit