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).
This commit is contained in:
Ed Zynda
2026-03-25 17:48:37 +03:00
parent db4bb19bac
commit 3446f38516
+15
View File
@@ -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")
}