Skip to content

Support clearing scrollback#31

Open
donbeave wants to merge 1 commit into
doy:mainfrom
donbeave:jackin-clear-scrollback
Open

Support clearing scrollback#31
donbeave wants to merge 1 commit into
doy:mainfrom
donbeave:jackin-clear-scrollback

Conversation

@donbeave

Copy link
Copy Markdown

Summary

This adds a narrow scrollback-clearing path to vt100:

  • Screen::clear_scrollback() clears the active screen's saved scrollback and returns the scrollback view to the live viewport.
  • CSI 3 J is handled as xterm's "erase saved lines" operation.
  • The visible grid is left intact, and terminal modes are not reset.

I also included two small CI hygiene updates so this PR can run cleanly against the current workflow: the existing example loop is adjusted for current clippy, and the lockfile updates the dev-only rand entry from 0.9.1 to 0.9.4 to clear the current RustSec advisory reported by cargo deny.

Motivation

vt100 already models the terminal screen, scrollback, and parser state for consumers building terminal wrappers/multiplexers. Those consumers need to distinguish "clear saved lines" from heavier reset-style behavior:

  • CSI 3 J should clear scrollback.
  • It should not erase the visible screen.
  • It should not reset modes such as application cursor, cursor visibility, mouse reporting, or bracketed paste.

That makes this fit vt100's existing responsibility better than forcing each downstream consumer to reach into local state or fake a terminal reset.

This is intentionally narrower than #22. That PR proposed broader scrollback inspection APIs. This PR only adds the missing clear operation and terminal escape handling, without exposing scrollback rows or internal row types.

Tests

Added coverage in tests/scroll.rs for:

  • direct Screen::clear_scrollback() behavior;
  • CSI 3 J clearing saved lines;
  • preserving visible contents after CSI 3 J;
  • clamping/resetting the scrollback offset after clear;
  • preserving application cursor, hidden cursor, mouse reporting, SGR mouse encoding, and bracketed paste after CSI 3 J.

Local verification

  • cargo fmt --check
  • cargo test
  • cargo clippy --all-targets -- -D warnings
  • cargo build --all-targets
  • cargo doc --no-deps
  • rustup run 1.70.0 cargo check --lib --all-features
  • cargo deny check

Add Screen::clear_scrollback and handle CSI 3 J as xterm's erase saved lines sequence. This lets embedders clear scrollback through terminal semantics without resetting parser state.

Co-authored-by: Codex <codex@openai.com>
@donbeave donbeave closed this May 22, 2026
@donbeave donbeave reopened this May 22, 2026
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