Skip to content

Fix terminal loader flicker and layout shifts - #19

Merged
letmutex merged 2 commits into
mainfrom
fix/terminal-flicker
Jul 20, 2026
Merged

letmutex merged 2 commits into
mainfrom
fix/terminal-flicker

Conversation

@letmutex

@letmutex letmutex commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Improved terminal rendering during window resizing.
    • Prevented text wrapping past the available terminal width.
    • Improved truncation for colored (ANSI) output, including status lines.
    • Reduced flicker by writing updates in-place and using synchronized terminal refreshes.
    • Fixed an extra blank line in account-switch status output.
  • Enhancements
    • Smoother animated loader behavior with updated timing and less screen flashing.
    • Improved screen clearing and more efficient frame rendering.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 22cb909e-3e76-4f67-ae8f-c25cafcef1a2

📥 Commits

Reviewing files that changed from the base of the PR and between 9a1fffa and 12e8a1e.

📒 Files selected for processing (2)
  • src/commands/list.rs
  • src/tui.rs
💤 Files with no reviewable changes (1)
  • src/commands/list.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tui.rs

📝 Walkthrough

Walkthrough

Terminal 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.

Changes

Terminal rendering

Layer / File(s) Summary
Width-aware rendering helpers
src/tui.rs, src/commands/list.rs
ANSI-aware width measurement and truncation are applied to frame and status output, with unit tests covering colored, truncated, and unchanged lines.
Frame lifecycle and resize handling
src/commands/list.rs
The list loop reserves transient terminal space, re-renders on resize events, and synchronizes frame drawing and clearing operations.
Loader and status output
src/tui.rs
Loader frames rewrite a truncated spinner row directly, while status and line-clearing helpers use synchronized terminal updates.

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
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main user-facing change: reducing terminal flicker and layout shifts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/terminal-flicker

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 win

Redundant "extra lines" clearing block.

Lines 184-195 explicitly clear/print extra old lines and move back up, but the unconditional Clear(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 win

Consider unicode-width instead 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-width is 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

📥 Commits

Reviewing files that changed from the base of the PR and between ba29b34 and 9a1fffa.

📒 Files selected for processing (2)
  • src/commands/list.rs
  • src/tui.rs

Comment thread src/tui.rs Resolved
@letmutex
letmutex merged commit 0c31fb7 into main Jul 20, 2026
2 checks passed
@letmutex
letmutex deleted the fix/terminal-flicker branch July 20, 2026 07:53
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