diff options
| author | adamdottv <[email protected]> | 2025-05-30 12:29:27 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-30 12:29:27 -0500 |
| commit | 6ebbcb3179119e6e2e1c35e41eb20ed283c0952c (patch) | |
| tree | a97412b7ff3777351b074d7525609756d1775e26 /internal/tui | |
| parent | 437de4ee36cc66e94c7b615f193ea53058c843b1 (diff) | |
| download | opencode-6ebbcb3179119e6e2e1c35e41eb20ed283c0952c.tar.gz opencode-6ebbcb3179119e6e2e1c35e41eb20ed283c0952c.zip | |
wip: refactoring tui
Diffstat (limited to 'internal/tui')
| -rw-r--r-- | internal/tui/components/chat/message.go | 38 | ||||
| -rw-r--r-- | internal/tui/styles/markdown.go | 1 |
2 files changed, 31 insertions, 8 deletions
diff --git a/internal/tui/components/chat/message.go b/internal/tui/components/chat/message.go index dbdbe2d3c..feed7ec59 100644 --- a/internal/tui/components/chat/message.go +++ b/internal/tui/components/chat/message.go @@ -2,6 +2,7 @@ package chat import ( "fmt" + "path/filepath" "strings" "time" @@ -160,7 +161,8 @@ func renderAssistantMessage( title, " In progress...", )) - messages = append(messages, content) + message := styles.ForceReplaceBackgroundWithLipgloss(content, t.Background()) + messages = append(messages, message) case client.MessageToolInvocationToolResult: toolInvocationResult := toolInvocation.(client.MessageToolInvocationToolResult) @@ -172,26 +174,48 @@ func renderAssistantMessage( } params := renderParams(width-lipgloss.Width(toolName)-1, toolArgs...) title := styles.Padded().Render(fmt.Sprintf("%s: %s", toolName, params)) + metadata := msg.Metadata.Tool[toolInvocationResult.ToolCallId].(map[string]any) - var trimmedDiff string + var markdown string if toolInvocationResult.ToolName == "edit" { filename := toolMap["filePath"].(string) + title = styles.Padded().Render(fmt.Sprintf("%s: %s", toolName, filename)) oldString := toolMap["oldString"].(string) newString := toolMap["newString"].(string) patch, _, _ := diff.GenerateDiff(oldString, newString, filename) formattedDiff, _ := diff.FormatDiff(patch, diff.WithTotalWidth(width)) - trimmedDiff = strings.TrimSpace(formattedDiff) + markdown = strings.TrimSpace(formattedDiff) message := toolStyle.Render(lipgloss.JoinVertical(lipgloss.Left, - toolName, - trimmedDiff, + title, + markdown, )) messages = append(messages, message) + } else if toolInvocationResult.ToolName == "view" { + result := toolInvocationResult.Result + if metadata["preview"] != nil { + result = metadata["preview"].(string) + } + filename := toolMap["filePath"].(string) + ext := filepath.Ext(filename) + if ext == "" { + ext = "" + } else { + ext = strings.ToLower(ext[1:]) + } + result = fmt.Sprintf("```%s\n%s\n```", ext, truncateHeight(result, 10)) + markdown = toMarkdown(result, width) + content := toolStyle.Render(lipgloss.JoinVertical(lipgloss.Left, + title, + markdown, + )) + message := styles.ForceReplaceBackgroundWithLipgloss(content, t.Background()) + messages = append(messages, message) } else { result := truncateHeight(strings.TrimSpace(toolInvocationResult.Result), 10) - trimmedDiff = toMarkdown(result, width) + markdown = toMarkdown(result, width) content := toolStyle.Render(lipgloss.JoinVertical(lipgloss.Left, title, - trimmedDiff, + markdown, )) message := styles.ForceReplaceBackgroundWithLipgloss(content, t.Background()) messages = append(messages, message) diff --git a/internal/tui/styles/markdown.go b/internal/tui/styles/markdown.go index 9693cfbba..77fb51bae 100644 --- a/internal/tui/styles/markdown.go +++ b/internal/tui/styles/markdown.go @@ -163,7 +163,6 @@ func generateMarkdownStyleConfig() ansi.StyleConfig { Prefix: " ", Color: stringPtr(adaptiveColorToString(t.MarkdownCodeBlock())), }, - Margin: uintPtr(defaultMargin), }, Chroma: &ansi.Chroma{ Text: ansi.StylePrimitive{ |
