Skip to content

fix(cli): preserve startup banner on terminal resize#23048

Closed
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/cli-resize-preserve-banner
Closed

fix(cli): preserve startup banner on terminal resize#23048
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/cli-resize-preserve-banner

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Problem

After starting the classic CLI in a small terminal window and then maximizing/resizing, the startup banner and right-side tool summary disappear. Only the bottom input prompt area remains visible.

Root cause: _recover_after_resize() calls _clear_prompt_toolkit_screen(app, rebuild_scrollback=True) which sends erase_screen() + �[3J] (clear scrollback). The startup banner was printed before prompt_toolkit owned the chrome, so it lives in normal terminal scrollback — clearing it removes the banner permanently. _replay_output_history cannot reconstruct it because the banner was never added to _OUTPUT_HISTORY.

Fix

Replace the aggressive screen/scrollback clear with a minimal renderer reset:

  • app.renderer.reset(leave_alternate_screen=False) — drops prompt_toolkit's cached screen + cursor state so the next redraw starts clean
  • app.invalidate() — schedules a repaint
  • original_on_resize() — recalculates layout for the new terminal size

This matches how bash/zsh/fish/vim/htop handle SIGWINCH — they never clear scrollback on resize.

Before vs After

Scenario Before After
Resize terminal Banner disappears, only prompt visible Banner preserved, layout adapts
_force_full_redraw (Ctrl+L) Full clear + replay (unchanged) Same — explicit redraw still clears
Exception safety _clear_prompt_toolkit_screen wrapped in try/except Same — both try/except blocks swallow errors

Tests

Updated test_resize_rebuilds_scrollback_before_prompt_toolkit_redrawtest_resize_preserves_scrollback_and_resets_renderer to verify:

  • renderer.reset() + invalidate() + original_on_resize() called in order
  • erase_screen, write_raw, cursor_goto NOT called (scrollback preserved)

All 9 tests in tests/cli/test_cli_force_redraw.py pass.


Fixes #22999

Recover from SIGWINCH without clearing the physical screen or scrollback
buffer. The startup banner and tool summary are printed before
prompt_toolkit owns the live chrome, so they live in normal terminal
scrollback. Calling erase_screen() + \x1b[3J] on every resize removed
that UI permanently — _replay_output_history cannot reconstruct it
because the banner was never added to _OUTPUT_HISTORY.

Instead, just reset prompt_toolkit's renderer cache and invalidate so
the next incremental redraw starts from a clean slate, then let the
original on_resize handler recalculate layout for the new terminal
size. This matches the behaviour of bash/zsh/fish on SIGWINCH.

Fixes NousResearch#22999
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have labels May 10, 2026
@liw71750-dotcom

Copy link
Copy Markdown

This PR addresses one specific symptom of a broader issue: the CLI/TUI does not reflow content on terminal resize. There are 34+ open bugs about various manifestations of this problem.

I've opened a tracking feature request (#24164) that proposes a comprehensive solution — a SIGWINCH handler triggering full re-render at new viewport dimensions, comparable to how opencode and Claude Code handle resize smoothly.

If this PR gets merged, please consider whether the underlying architecture supports full reflow, or if we still need a systematic fix. The tracking issue consolidates all related work:

#24164

@teknium1

Copy link
Copy Markdown
Contributor

Salvaged onto current main via #25227 (your branch was 219 commits behind; cherry-picked with your authorship preserved in git log).

Commit e2b2d48 on main, author vominh1919 vominh1919@gmail.com. Thanks for the fix — and to @Dc-j0e for the well-diagnosed bug report.

@teknium1 teknium1 closed this May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Classic CLI resize clears startup banner/tool summary after terminal maximize

4 participants