8000 Reset terminal state leaves the alternate screen while the program is still running · Issue #347 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

Reset terminal state leaves the alternate screen while the program is still running #347

Closed

Description

@jpstratman

What happens

Reset terminal state (Ctrl+Shift+R, or the command palette) calls resetTerminalModes. When the pane is on the alternate buffer, terminalResetSequence(true) starts with ESC[?1049l, which switches xterm back to the normal buffer.

That is right for the case the command was written for (#175): the program that entered the alternate screen has died, and the pane is stuck in its modes. But the wmux:reset-terminal handler in useTerminal.ts runs whenever the PTY is present, including while the program is still running. A running fullscreen program (Claude Code, opencode, vim) never re-sends ESC[?1049h, because from its side nothing happened. The result is the same as #345:

  • the program's next frames are drawn into the normal buffer and its scrollback
  • a full-screen clear from the program wipes the shell's own lines
  • when the program exits, its ESC[?1049l has no alternate screen to leave and only restores the cursor, so the shell prompt is printed over the stale frame

The resetTerminalModes doc comment expects a live program to put back the modes it wants ("reset while vim is up and vim repaints"). That holds for modes a program re-asserts on every redraw. It doesn't hold for the alternate screen.

Steps to reproduce

I found this by reading the code and haven't reproduced it in the app. Expected reproduction:

  1. In a terminal pane, run:
    cls; "MAIN-1"; "MAIN-2"; [Console]::Write("`e[?1049h`e[H"); 1..5|%{"ALT-BEFORE-$_"}; Start-Sleep 15; 1..5|%{"ALT-AFTER-$_"}; Start-Sleep 3; [Console]::Write("`e[?1049l"); "EXITED"
  2. While it sleeps, press Ctrl+Shift+R in that pane.
  3. Expected bug: ALT-AFTER-1..5 land on the normal screen, and on exit EXITED and the prompt are printed at the top over the old content.

Possible fixes

  • Leave the alternate buffer only when the program is gone: keep ESC[?1049l on the process-exit path and drop it from the manual reset. A pane whose program is still running stays on the screen that program is drawing.
  • Or decide per pane with the shell state wmux already tracks (OSC 133). Leave the alternate buffer when the shell is back at its prompt, and keep it while a command is running.

wmux version

2.39.0

Anything else

Related: #175 (where the reset was added) and #345 (same end state, reached through a remount).

Activity

  1. amirlehmam commented on Oct 24, 2026

    @amirlehmam
    Owner

    Shipped in v2.40.0. Thanks for the detailed report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0