From 3446f38516d7b58e68738bc36d3bdfdef475916d Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Wed, 25 Mar 2026 17:48:37 +0300 Subject: [PATCH] feat(ui): add line truncation to Ls tool renderer Add maxLsLines (20) constant and truncate Ls output in the TUI to prevent large directory listings from blowing up the layout. Shows a '...(N more entries)' hint when truncated, consistent with all other core tool renderers (Edit, Read, Write, Bash, Subagent). --- internal/ui/tool_renderers.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/ui/tool_renderers.go b/internal/ui/tool_renderers.go index 0a0fd4a7..b5f6f2dc 100644 --- a/internal/ui/tool_renderers.go +++ b/internal/ui/tool_renderers.go @@ -23,6 +23,7 @@ const ( maxCodeLines = 20 // lines for Read / code blocks maxWriteLines = 10 // lines for Write blocks maxBashLines = 20 // lines for Bash output (matches Read) + maxLsLines = 20 // lines for Ls directory listings ) // renderToolBody dispatches to tool-specific body renderers based on tool name. @@ -315,6 +316,13 @@ func renderLsBody(toolResult string, width int) string { lines := strings.Split(content, "\n") + // Truncate to maxLsLines for display + var hiddenCount int + if len(lines) > maxLsLines { + hiddenCount = len(lines) - maxLsLines + lines = lines[:maxLsLines] + } + const indent = " " codeWidth := max(width-len(indent), 20) @@ -329,6 +337,13 @@ func renderLsBody(toolResult string, width int) string { result = append(result, indent+styled) } + if hiddenCount > 0 { + hint := fmt.Sprintf("...(%d more entries)", hiddenCount) + hintContent := codeStyle.Width(codeWidth). + Foreground(theme.Muted).Italic(true).Render(hint) + result = append(result, indent+hintContent) + } + return strings.Join(result, "\n") }