Skip to content

feat: add scrollback buffer and scroll wheel support to embedded terminal#349

Merged
Wirasm merged 2 commits into
mainfrom
kild/311-scrollback-buffer
Feb 11, 2026
Merged

feat: add scrollback buffer and scroll wheel support to embedded terminal#349
Wirasm merged 2 commits into
mainfrom
kild/311-scrollback-buffer

Conversation

@Wirasm

@Wirasm Wirasm commented Feb 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Wire GPUI ScrollWheelEvent to alacritty_terminal's scroll_display() via hitbox-based mouse event listener in TerminalElement
  • Support both trackpad (pixel deltas) and mouse wheel (line deltas) scrolling
  • Show a "Scrollback" badge at top-right when scrolled up from bottom

The 10,000-line scrollback buffer was already provided by TermConfig::default() — this adds the scroll UI to make it accessible.

Closes #311

Test plan

  • Open terminal, run seq 200, scroll wheel up — earlier lines visible
  • Scroll wheel down — returns to bottom
  • "Scrollback" badge appears when scrolled up, disappears at bottom
  • New output auto-scrolls when already at bottom
  • Trackpad smooth scroll works (pixel deltas)
  • Mouse wheel discrete scroll works (line deltas)
  • No crash on scroll with empty terminal (no history)

…inal

Wire GPUI ScrollWheelEvent to alacritty_terminal's scroll_display() via
a hitbox-based mouse event listener in TerminalElement. Supports both
trackpad (pixel deltas) and mouse wheel (line deltas).

Add a "Scrollback" badge at top-right when scrolled up from bottom so
users know they're viewing history. The badge disappears when scrolled
back to bottom.

The 10,000-line scrollback buffer was already provided by
TermConfig::default() — this change just adds the scroll UI.

Closes #311
@Wirasm

Wirasm commented Feb 11, 2026

Copy link
Copy Markdown
Owner Author

PR Review Summary

Reviewed by: code-reviewer, silent-failure-hunter, comment-analyzer, pr-test-analyzer

Critical Issues (0 found)

None.

Important Issues (0 found)

None. The code reviewer flagged handler registration in paint() as a potential memory leak, but this is a false positive — GPUI manages mouse event handlers per-frame. Registering in paint() is the standard GPUI pattern (matches Zed's own terminal element).

Suggestions (1 found)

Agent Suggestion Location
code-reviewer Consider visual fallback if badge text paint fails (currently logs error, which is sufficient) terminal_element.rs:582-589

Strengths

  • Clean GPUI patterns: hitbox in prepaint, event handler in paint, proper phase/bounds checking
  • Correct coordinate system translation between GPUI (negative y = up) and alacritty (positive Delta = up), with clear comment explaining the mapping
  • Well-structured layer comments (Layers 1-5) documenting the painter's algorithm rendering order
  • Safe numeric conversions: f32 → i32 saturates (no panic), lines != 0 guard prevents no-op calls
  • Proper error handling: badge paint failure logged with structured event name following project conventions
  • No silent failures detected — all error paths properly surface issues

Error Handling Assessment

  • PASS — zero silent failures. Badge paint error is logged. Scroll handler has no fallible operations (FairMutex can't poison, scroll_display can't fail, float-to-int saturates).

Comment Quality

  • GOOD — all 3 new comments are factually accurate. Layer numbering verified (1-5 complete). Scroll direction comment verified against both GPUI and alacritty conventions.

Test Coverage

  • ADEQUATE — no unit tests added, which is correct. GPUI Element implementations require live rendering context (Window, App, text system) that isn't practical to mock. The manual test plan covers all critical behaviors (scroll up/down, badge visibility, trackpad vs mouse wheel, empty terminal edge case). This matches the existing testing pattern where pure logic (colors, input) has unit tests while Element/View code uses manual verification.

Verdict

READY TO MERGE

Recommended Actions

  1. Execute the manual test plan from the PR description
  2. No code changes needed

Paint a thin accent bar when badge text rendering fails so the user
still gets a visible "scrolled up" indicator.
@Wirasm Wirasm merged commit 63555c8 into main Feb 11, 2026
6 checks passed
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.

kild-ui: scrollback buffer and scroll interaction for embedded terminals

1 participant