Skip to content

Commit 5121375

Browse files
committed
tui(edit_file): render tool error on a single line with consistent styling
Signed-off-by: pnkcaht <samzoovsk19@gmail.com>
1 parent 1c5bb9b commit 5121375

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

pkg/tui/components/tool/editfile/editfile.go

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func New(msg *types.Message, sessionState *service.SessionState) layout.Model {
2222

2323
// render displays the edit_file tool output in the TUI.
2424
// It prioritizes the agent-provided friendly header when available,
25-
// hides results when collapsed by the user, and skips diff rendering
26-
// on tool execution errors to avoid layout issues.
25+
// hides results when collapsed by the user, and renders tool errors
26+
// in a single-line error style consistent with other tools.
2727
func render(
2828
msg *types.Message,
2929
s spinner.Spinner,
@@ -38,6 +38,32 @@ func render(
3838
return ""
3939
}
4040

41+
// When the tool failed, render a single-line error header
42+
// consistent with other tool error renderings.
43+
if msg.ToolStatus == types.ToolStatusError {
44+
if msg.Content == "" {
45+
return ""
46+
}
47+
48+
// Render everything on a single line:
49+
// - error icon
50+
// - tool name in error style
51+
// - rejection/error message
52+
line := fmt.Sprintf(
53+
"%s%s %s",
54+
styles.ToolErrorIcon.Render("✖ "),
55+
styles.ToolNameError.Render(msg.ToolDefinition.DisplayName()),
56+
styles.ToolErrorMessageStyle.Render(msg.Content),
57+
)
58+
59+
// Truncate to terminal width to avoid wrapping
60+
return styles.BaseStyle.
61+
MaxWidth(width).
62+
Render(line)
63+
}
64+
65+
// ---- Normal (non-error) rendering ----
66+
4167
// Check for friendly description first
4268
var content string
4369
if header, ok := toolcommon.RenderFriendlyHeader(msg, s); ok {
@@ -56,25 +82,6 @@ func render(
5682
return content
5783
}
5884

59-
// When the edit fails, do not render a diff.
60-
// Instead, render the error/rejection as a single-line tool message.
61-
// Rendering diffs on failed edits can break layout and scroll calculations.
62-
if msg.ToolStatus == types.ToolStatusError {
63-
if msg.Content != "" {
64-
// Render error/rejection as a single-line tool error message
65-
// with consistent spacing and styling.
66-
errorText := fmt.Sprintf(" %s", msg.Content)
67-
68-
// Truncate to available width to avoid wrapping
69-
errorLine := styles.ToolErrorMessageStyle.
70-
MaxWidth(width).
71-
Render(errorText)
72-
73-
content += "\n" + errorLine
74-
}
75-
return content
76-
}
77-
7885
// Successful (or pending/confirmation) execution:
7986
// render the diff output inside the ToolCallResult container.
8087
if msg.ToolCall.Function.Arguments != "" {

0 commit comments

Comments
 (0)