Fix bash tool visual line truncation

Use visual line counting (accounting for line wrapping) instead of logical
line counting for bash tool output in collapsed mode. Now consistent with
bash-execution.ts behavior.

- Add shared truncateToVisualLines utility
- Update tool-execution.ts to use Box for bash with visual truncation
- Update bash-execution.ts to use shared utility
- Pass TUI to ToolExecutionComponent for terminal width access

Fixes #275
This commit is contained in:
Mario Zechner 2025-12-22 17:01:04 +01:00
parent 31f4a588fd
commit 7ad8a8c447
5 changed files with 163 additions and 58 deletions

View file

@ -12,6 +12,7 @@ import {
} from "../../../core/tools/truncate.js";
import { theme } from "../theme/theme.js";
import { DynamicBorder } from "./dynamic-border.js";
import { truncateToVisualLines } from "./visual-truncate.js";
// Preview line limit when not expanded (matches tool execution behavior)
const PREVIEW_LINES = 20;
@ -134,15 +135,15 @@ export class BashExecutionComponent extends Container {
const displayText = availableLines.map((line) => theme.fg("muted", line)).join("\n");
this.contentContainer.addChild(new Text(`\n${displayText}`, 1, 0));
} else {
// Render preview lines, then cap at PREVIEW_LINES visual lines
const tempText = new Text(
`\n${previewLogicalLines.map((line) => theme.fg("muted", line)).join("\n")}`,
1,
0,
// Use shared visual truncation utility
const styledOutput = previewLogicalLines.map((line) => theme.fg("muted", line)).join("\n");
const { visualLines } = truncateToVisualLines(
`\n${styledOutput}`,
PREVIEW_LINES,
this.ui.terminal.columns,
1, // padding
);
const visualLines = tempText.render(this.ui.terminal.columns);
const truncatedVisualLines = visualLines.slice(-PREVIEW_LINES);
this.contentContainer.addChild({ render: () => truncatedVisualLines, invalidate: () => {} });
this.contentContainer.addChild({ render: () => visualLines, invalidate: () => {} });
}
}