mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 06:04:51 +00:00
fix(tui): isImageLine should detect image escape sequences anywhere in line
Changed isImageLine() from using startsWith() to includes() to detect Kitty and iTerm2 image escape sequences anywhere in a line, not just at the start. This prevents TUI width checks from failing on lines containing image data, which could cause crashes when rendering tool results with images (e.g., when reading image files). Also added comprehensive test coverage for isImageLine() including: - Both iTerm2 and Kitty protocols - Regression tests for long lines and terminals without image support - Negative cases to ensure no false positives Fixes crash: 'Rendered line exceeds terminal width' when image escape sequences appear in output.
This commit is contained in:
parent
2cee7e17de
commit
2339d7b5ac
3 changed files with 160 additions and 15 deletions
|
|
@ -79,24 +79,12 @@ export function getCapabilities(): TerminalCapabilities {
|
|||
|
||||
export function resetCapabilitiesCache(): void {
|
||||
cachedCapabilities = null;
|
||||
imageEscapePrefix = undefined;
|
||||
}
|
||||
|
||||
let imageEscapePrefix: string | null | undefined;
|
||||
|
||||
function getImageEscapePrefix(): string | null {
|
||||
if (imageEscapePrefix === undefined) {
|
||||
const protocol = getCapabilities().images;
|
||||
if (protocol === "kitty") imageEscapePrefix = "\x1b_G";
|
||||
else if (protocol === "iterm2") imageEscapePrefix = "\x1b]1337;File=";
|
||||
else imageEscapePrefix = null;
|
||||
}
|
||||
return imageEscapePrefix;
|
||||
}
|
||||
|
||||
export function isImageLine(line: string): boolean {
|
||||
const prefix = getImageEscapePrefix();
|
||||
return prefix !== null && line.startsWith(prefix);
|
||||
// Check for Kitty or iTerm2 image escape sequences anywhere in the line
|
||||
// This prevents width checks from failing on lines containing image data
|
||||
return line.includes("\x1b_G") || line.includes("\x1b]1337;File=");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue