summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-30 06:03:34 -0500
committeradamdottv <[email protected]>2025-05-30 06:03:34 -0500
commitb1b402faa7616a4dd976a2a79e57ae0334ab509b (patch)
tree81366831e6962782c1db4c741d4d81713df41adb
parentc5413c8c8dc2c05afcd766c9e9a92a8e541aa403 (diff)
downloadopencode-b1b402faa7616a4dd976a2a79e57ae0334ab509b.tar.gz
opencode-b1b402faa7616a4dd976a2a79e57ae0334ab509b.zip
wip: refactoring tui
-rw-r--r--internal/tui/components/chat/message.go24
-rw-r--r--internal/tui/components/chat/messages.go16
2 files changed, 19 insertions, 21 deletions
diff --git a/internal/tui/components/chat/message.go b/internal/tui/components/chat/message.go
index 1dcdf8e46..dbdbe2d3c 100644
--- a/internal/tui/components/chat/message.go
+++ b/internal/tui/components/chat/message.go
@@ -77,7 +77,7 @@ func renderUserMessage(msg client.MessageInfo, width int) string {
}
}
- return content
+ return styles.ForceReplaceBackgroundWithLipgloss(content, t.Background())
}
func convertToMap(input *any) (map[string]any, bool) {
@@ -133,7 +133,8 @@ func renderAssistantMessage(
textPart := part.(client.MessagePartText)
text := toMarkdown(textPart.Text, width)
content := style.Render(lipgloss.JoinVertical(lipgloss.Left, text, info))
- messages = append(messages, content)
+ message := styles.ForceReplaceBackgroundWithLipgloss(content, t.Background())
+ messages = append(messages, message)
case client.MessagePartToolInvocation:
if !showToolMessages {
@@ -172,27 +173,28 @@ func renderAssistantMessage(
params := renderParams(width-lipgloss.Width(toolName)-1, toolArgs...)
title := styles.Padded().Render(fmt.Sprintf("%s: %s", toolName, params))
- var markdown string
+ var trimmedDiff string
if toolInvocationResult.ToolName == "edit" {
filename := toolMap["filePath"].(string)
oldString := toolMap["oldString"].(string)
newString := toolMap["newString"].(string)
patch, _, _ := diff.GenerateDiff(oldString, newString, filename)
formattedDiff, _ := diff.FormatDiff(patch, diff.WithTotalWidth(width))
- markdown = truncateHeight(strings.TrimSpace(formattedDiff), 10)
- content := toolStyle.Render(lipgloss.JoinVertical(lipgloss.Left,
+ trimmedDiff = strings.TrimSpace(formattedDiff)
+ message := toolStyle.Render(lipgloss.JoinVertical(lipgloss.Left,
toolName,
- markdown,
+ trimmedDiff,
))
- messages = append(messages, content)
+ messages = append(messages, message)
} else {
result := truncateHeight(strings.TrimSpace(toolInvocationResult.Result), 10)
- markdown = toMarkdown(result, width)
+ trimmedDiff = toMarkdown(result, width)
content := toolStyle.Render(lipgloss.JoinVertical(lipgloss.Left,
title,
- markdown,
+ trimmedDiff,
))
- messages = append(messages, content)
+ message := styles.ForceReplaceBackgroundWithLipgloss(content, t.Background())
+ messages = append(messages, message)
}
}
}
@@ -265,7 +267,7 @@ func renderToolName(name string) string {
case "ls":
return "List"
default:
- return cases.Title(language.English).String(name)
+ return cases.Title(language.Und).String(name)
}
}
diff --git a/internal/tui/components/chat/messages.go b/internal/tui/components/chat/messages.go
index 50a0f4200..0dda7ae32 100644
--- a/internal/tui/components/chat/messages.go
+++ b/internal/tui/components/chat/messages.go
@@ -101,7 +101,6 @@ func (m *messagesCmp) renderView() {
return
}
- t := theme.CurrentTheme()
messages := make([]string, 0)
for _, msg := range m.app.Messages {
switch msg.Role {
@@ -115,16 +114,13 @@ func (m *messagesCmp) renderView() {
}
m.viewport.SetContent(
- styles.ForceReplaceBackgroundWithLipgloss(
- styles.BaseStyle().
- Render(
- lipgloss.JoinVertical(
- lipgloss.Top,
- messages...,
- ),
+ styles.BaseStyle().
+ Render(
+ lipgloss.JoinVertical(
+ lipgloss.Top,
+ messages...,
),
- t.Background(),
- ),
+ ),
)
}