Skip to content

Filter UI chrome out of cmd.exe / Windows Terminal review output#13

Open
serrebidev wants to merge 3 commits into
ruifontes:masterfrom
serrebidev:fix/terminal-chrome-cleanup
Open

Filter UI chrome out of cmd.exe / Windows Terminal review output#13
serrebidev wants to merge 3 commits into
ruifontes:masterfrom
serrebidev:fix/terminal-chrome-cleanup

Conversation

@serrebidev
Copy link
Copy Markdown

Summary

When the focused UWP window hosts a TermControl child (cmd.exe, PowerShell, etc. running inside Windows Terminal), obtainUWPWindowText() appended every non-None child element name during the tree walk. For a typical cmd.exe window that produces output like:

C:\WINDOWS\system32\cmd.exe
C:\WINDOWS\system32\cmd.exe
C:\WINDOWS\system32\cmd.exe
Close Tab
C:\WINDOWS\system32\cmd.exe
Microsoft Windows [Version 10.0.26200.8457]
(c) Microsoft Corporation. All rights reserved.

C:\Users\admin>
Vertical Small Decrease
Vertical Large Decrease
Vertical Large Increase
Vertical Small Increase
System

The window title repeats as several child element names, and the tab Close button, the four scroll-bar parts, and the System menu all get interleaved with the actual terminal output.

This change detects a TermControl during the walk; when one is present anywhere in the foreground window, the function returns just [title, terminal text] and drops the chrome. Non-terminal UWP apps (Start menu, Settings, etc.) fall through to the existing behavior unchanged, so there's no regression risk for those.

A small _isTermControl helper is extracted since the same hasattr / UIAElement / currentClassName check now needs to happen in three places.

Test plan

  • Modern cmd.exe (Windows Terminal-hosted) — title + terminal text only, no chrome
  • Legacy ConsoleWindowClass cmd window — unchanged (handled by separate code path)
  • Start menu / Settings / Calculator — unchanged (no TermControl present, falls through)

🤖 Generated with Claude Code

admin added 3 commits May 15, 2026 19:06
When the focused UWP window hosts a TermControl child (cmd.exe and other
shells running inside Windows Terminal), obtainUWPWindowText() previously
appended every non-None child name during the tree walk. That pulled in
the window title repeated as child element names, the "Close Tab" button,
the four scroll-bar parts ("Vertical Small/Large Decrease/Increase"), and
the "System" menu — all interleaved with the actual terminal text.

Detect TermControl during the walk; when one is present anywhere in the
foreground window, return only [title, terminal text] and drop the chrome.
Non-terminal UWP apps fall through to the existing behavior unchanged.
In addition to the chrome elements stripped above, capturing the full
TermControl story also returns space-padded blank rows for any visible
terminal cell that hasn't been written to. TUI apps such as Claude Code,
vim, htop, lazygit etc. paint content at the top of the buffer and a
status/input row at the bottom, leaving a large empty band in the middle
that becomes a long run of blank lines in the review window.

Add _cleanTerminalText() that:
  - Strips per-line trailing whitespace (removes the column padding)
  - Collapses 2+ consecutive blank lines into a single blank line
  - rstrips the final result

This preserves intentional single-blank-line spacing (e.g. the blank
between "All rights reserved." and the cmd prompt) while eliminating the
long visual gap, and tightens cmd output as a side benefit.
The previous commit collapsed runs of blank padding to a single blank
line, but in TUI apps that paint boxed UIs (Claude Code, lazygit, gh
dash) every box-row gap also produces "│   │" lines that aren't blank
and so survive the collapse. Reviewing the result line-by-line still
required pressing arrow keys through dozens of decorative rows between
content paragraphs.

Replace the collapse logic with a stricter filter: after per-line
rstrip, drop any line whose only non-whitespace characters are in the
Unicode Box Drawing block (U+2500-U+257F). Truly blank lines fall under
the same predicate (empty stripped == decorative) so they're removed
too. Content lines that include "│" borders survive because the letters
between the borders fall outside the range.

Tradeoff: cmd output loses its single-blank line between the copyright
banner and the prompt. For the audience most affected (NVDA users
navigating the review window with up/down arrow), eliminating the
decorative-line wading is the bigger win.
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