feat: add --color flag for ANSI escape sequence passthrough#2
Conversation
…wait output tui-use strips all color and style information from terminal output, which is documented as a known limitation. This adds an opt-in --color flag to the snapshot and wait commands that re-encodes xterm buffer cell attributes back into ANSI SGR escape sequences. Supports the full range of terminal styling: 8/16/256-color palette, 24-bit RGB, bold, dim, italic, underline, blink, inverse, and strikethrough. Default behavior is unchanged — plain text unless --color is specified. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@phiat Thank you for you contribution? Btw, why this tool and color mode is useful for you? |
|
I'm building claude-esp, a TUI that streams Claude Code's hidden output (thinking, tool calls, subagents) to a separate terminal. It uses Lipgloss/Bubbletea for styling — different colors for thinking blocks, tool headers, error states, etc. I've been using tui-use as test infrastructure to drive claude-esp and verify its rendering. The plain text snapshots work great for content assertions, but I couldn't test that styling was correct — e.g., that error text actually renders red, or that tool headers use the right color. With By the way — tui-use worked for me on first try. Thanks for building it, and thanks for resolving the conflicts in #6! |
Merge #2: Add --color flag to preserve ANSI escape sequences (with debounce fix)
Problem
tui-use strips all color and style information from terminal output. The README documents this as a known limitation:
This means agents can't distinguish between red error text and green success text, can't detect colored status indicators, and lose visual semantics that many CLI tools rely on to communicate state.
Solution
Add an opt-in
--colorflag tosnapshotandwaitthat re-encodes xterm buffer cell attributes back into ANSI SGR escape sequences. The xterm emulator already parses and stores all style data in its cell buffer — this feature reads it back out.Without
--color(unchanged):With
--color:What's supported
Design decisions
--colorflag must be explicitly passed.lastSnapshotalways stores plain text regardless of color mode, sowait()change detection works correctly whether or not color is enabled.Changes
session.ts— ANSI re-encoding helpers +coloroption onsnapshot()/wait()protocol.ts—color?: booleanonSnapshotRequest/WaitRequestdaemon.ts— passes color flag through to sessioncli.ts—--coloroption onsnapshotandwaitcommandsTesting
All 32 existing tests pass. Manually verified with:
echo -ewith explicit ANSI codes (8-color, bold, inverse)ls --color=always(256-color palette for directories/executables)htop(full-screen TUI with 486 escape sequences captured)