|
1 | 1 | package tool |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "fmt" |
5 | 6 | "log/slog" |
6 | 7 | "strings" |
@@ -125,24 +126,35 @@ func (mv *toolModel) View() string { |
125 | 126 | // Add tool result content if available (for completed tools with content) |
126 | 127 | var resultContent string |
127 | 128 | if (msg.ToolStatus == types.ToolStatusCompleted || msg.ToolStatus == types.ToolStatusError) && msg.Content != "" { |
| 129 | + var content string |
| 130 | + var m map[string]any |
| 131 | + if err := json.Unmarshal([]byte(msg.Content), &m); err != nil { |
| 132 | + content = msg.Content |
| 133 | + } else if buf, err := json.MarshalIndent(m, "", " "); err != nil { |
| 134 | + content = msg.Content |
| 135 | + } else { |
| 136 | + content = string(buf) |
| 137 | + } |
| 138 | + |
128 | 139 | // Calculate available width for content (accounting for padding) |
129 | 140 | padding := styles.ToolCallResult.Padding().GetHorizontalPadding() |
130 | 141 | availableWidth := max(mv.width-2-padding, 10) // Minimum readable width |
131 | 142 |
|
132 | 143 | // Wrap long lines to fit the component width |
133 | | - lines := wrapLines(msg.Content, availableWidth) |
| 144 | + lines := wrapLines(content, availableWidth) |
134 | 145 |
|
135 | 146 | // Take only first 10 lines after wrapping |
| 147 | + header := "output" |
136 | 148 | if len(lines) > 10 { |
137 | 149 | lines = lines[:10] |
138 | | - // Add indicator that content was truncated |
139 | | - lines = append(lines, wrapLines("... (output truncated)", availableWidth)...) |
| 150 | + header = "output (truncated)" |
| 151 | + lines = append(lines, wrapLines("...", availableWidth)...) |
140 | 152 | } |
141 | 153 |
|
142 | | - // Join the lines back and apply muted style |
| 154 | + // Join the lines back |
143 | 155 | trimmedContent := strings.Join(lines, "\n") |
144 | 156 | if trimmedContent != "" { |
145 | | - resultContent = "\n" + styles.ToolCallResult.Render(styles.ToolCallResultKey.Render("\n-> output:")+"\n"+trimmedContent) |
| 157 | + resultContent = "\n" + styles.ToolCallResult.Render(styles.ToolCallResultKey.Render("\n-> "+header+":")+"\n"+trimmedContent) |
146 | 158 | } |
147 | 159 | } |
148 | 160 |
|
|
0 commit comments