8000 Add “Clear terminal buffer” action by strayge · Pull Request #434 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

Add “Clear terminal buffer” action - #434

Merged
amirlehmam merged 2 commits into
amirlehmam:masterfrom
strayge:feat/clear-terminal-buffer
Nov 4, 2026
Merged

amirlehmam merged 2 commits into
amirlehmam:masterfrom
strayge:feat/clear-terminal-buffer

Conversation

@strayge
@strayge strayge commented Nov 4, 2026
Copy link
Copy Markdown
Contributor

Problem

wmux has no built-in way to clear terminal scrollback without restarting the shell.

Changes

  • Add “Clear terminal buffer” to the command palette.
  • Add a configurable shortcut, unbound by default.
  • Clear the focused terminal’s buffer while preserving its current cursor line.
  • Discard stale prompt markers and anchors, and guard against clearing during history replay.

Testing

  • Full test suite: 6,487 passed, 10 skipped.
  • Typecheck passes.
  • Manually verified by the contributor.

@strayge
strayge marked this pull request as ready for review November 4, 2026 02:21
strayge and others added 2 commits November 4, 2026 11:57
… skip the alternate screen

Review fixes for the Clear terminal buffer action (amirlehmam#434):

- Clear ConPTY's own screen copy before xterm's. A frontend-only clear left
  ConPTY's cursor on the old bottom row, so the next echoed keystroke came
  back as an absolute CUP to that row. New pty:clear IPC (preload ->
  PtyManager.clear -> node-pty clear()), accepted only from the window that
  owns a live PTY; a no-op where node-pty has no clear().
- Re-base, rather than delete, the prompt log's pending OSC 133 A/B state,
  so the command typed right after a clear at an idle prompt is still logged.
- Do nothing on the alternate screen, like Reset terminal state (amirlehmam#357).
- Replace the two tests that passed with the feature reverted, and add a real
  ConPTY test proving the echo lands on the kept row only with clear().

Also clears pre-existing Sonar findings in the touched files (nested
ternary and complexity in PtyManager.create, a redundant void, nested
callbacks in useTerminal and a test helper).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@amirlehmam
amirlehmam force-pushed the feat/clear-terminal-buffer branch from 1d284e1 to 3809e01 Compare November 4, 2026 10:58
@amirlehmam
Copy link
Copy Markdown
Owner

Thank you, this is a useful action and it was wired the right way: an unbound default, the palette entry, and stored keybindings merged over the defaults, so it reaches existing users.

Review found two problems on Windows when you clear at an idle prompt and then type, so I added a commit on top:

  • ConPTY desync. Clearing only xterm left ConPTY's own screen where it was, so the next echoed command was drawn back at the old bottom row. Checked with node-pty: without clear() ConPTY answers with ESC[10;35H, with it ESC[1;35H. The action now calls node-pty's clear() for the pane's PTY over a new IPC call, before clearing xterm, as VS Code does. Other backends are unaffected.
  • Prompt log. forgetSurface dropped the pending OSC 133 state, so the first command after a clear was never logged. That state is now moved to the kept row instead of deleted.
  • Alternate screen. It now does nothing inside a full-screen TUI, as reset-terminal does (Reset terminal state can't leave the alternate screen in panes that don't report shell state #357).

Each fix has a test that fails without it. Merging; it ships in the next release.

@amirlehmam
amirlehmam merged commit 72d246b into amirlehmam:master Nov 4, 2026
@strayge
strayge deleted the feat/clear-terminal-buffer branch November 8, 2026 18:03
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.

2 participants

0