fix: strip ANSI sequences when capturing tmux output without colors

Add stripAnsiSequences function to remove ANSI escape codes from terminal
output when includeColors is false. This ensures test assertions can match
against clean text without terminal formatting codes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-11-30 01:30:25 +00:00
parent 035a77f198
commit 143c0a0713

View File

@@ -46,6 +46,16 @@ export type ShellType = "bash" | "zsh" | "fish";
let shellConfig: { type: ShellType } = { type: "bash" };
const ANSI_ESCAPE_REGEX =
/\u001B[\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
function stripAnsiSequences(value: string): string {
if (!value) {
return "";
}
return value.replace(ANSI_ESCAPE_REGEX, "");
}
export function setShellConfig(config: { type: string }): void {
// Validate shell type
const validShells: ShellType[] = ["bash", "zsh", "fish"];
@@ -216,8 +226,9 @@ export async function capturePaneContent(
const trimmed = output.trimEnd();
const allLines = trimmed.split("\n");
const lastLines = allLines.slice(-lines);
const joined = lastLines.join("\n");
return lastLines.join("\n");
return includeColors ? joined : stripAnsiSequences(joined);
}
/**