chore(tui): simplify messages component, remove navigate, add copy last message

This commit is contained in:
adamdotdevin
2025-07-15 13:56:14 -05:00
parent f45deb37f0
commit d41aa2bc72
3 changed files with 51 additions and 160 deletions

View File

@@ -11,9 +11,7 @@ import (
"github.com/charmbracelet/lipgloss/v2/compat"
"github.com/sst/opencode-sdk-go"
"github.com/sst/opencode/internal/app"
"github.com/sst/opencode/internal/commands"
"github.com/sst/opencode/internal/components/diff"
"github.com/sst/opencode/internal/layout"
"github.com/sst/opencode/internal/styles"
"github.com/sst/opencode/internal/theme"
"github.com/sst/opencode/internal/util"
@@ -109,7 +107,6 @@ func WithPaddingBottom(padding int) renderingOption {
func renderContentBlock(
app *app.App,
content string,
highlight bool,
width int,
options ...renderingOption,
) string {
@@ -158,18 +155,6 @@ func renderContentBlock(
BorderRightBackground(t.Background())
}
if highlight {
style = style.
BorderLeftForeground(borderColor).
BorderRightForeground(borderColor)
}
}
if highlight {
style = style.
Foreground(t.Text()).
Background(t.BackgroundElement()).
Bold(true)
}
content = style.Render(content)
@@ -184,32 +169,6 @@ func renderContentBlock(
}
}
if highlight {
copy := app.Key(commands.MessagesCopyCommand)
// revert := app.Key(commands.MessagesRevertCommand)
background := t.Background()
header := layout.Render(
layout.FlexOptions{
Background: &background,
Direction: layout.Row,
Justify: layout.JustifyCenter,
Align: layout.AlignStretch,
Width: width - 2,
Gap: 5,
},
layout.FlexItem{
View: copy,
},
// layout.FlexItem{
// View: revert,
// },
)
header = styles.NewStyle().Background(t.Background()).Padding(0, 1).Render(header)
content = "\n\n\n" + header + "\n\n" + content + "\n\n\n"
}
return content
}
@@ -219,7 +178,6 @@ func renderText(
text string,
author string,
showToolDetails bool,
highlight bool,
width int,
extra string,
toolCalls ...opencode.ToolPart,
@@ -228,9 +186,6 @@ func renderText(
var ts time.Time
backgroundColor := t.BackgroundPanel()
if highlight {
backgroundColor = t.BackgroundElement()
}
var content string
switch casted := message.(type) {
case opencode.AssistantMessage:
@@ -277,7 +232,6 @@ func renderText(
return renderContentBlock(
app,
content,
highlight,
width,
WithTextColor(t.Text()),
WithBorderColorRight(t.Secondary()),
@@ -286,7 +240,6 @@ func renderText(
return renderContentBlock(
app,
content,
highlight,
width,
WithBorderColor(t.Accent()),
)
@@ -297,7 +250,6 @@ func renderText(
func renderToolDetails(
app *app.App,
toolCall opencode.ToolPart,
highlight bool,
width int,
) string {
ignoredTools := []string{"todoread"}
@@ -307,7 +259,7 @@ func renderToolDetails(
if toolCall.State.Status == opencode.ToolPartStateStatusPending {
title := renderToolTitle(toolCall, width)
return renderContentBlock(app, title, highlight, width)
return renderContentBlock(app, title, width)
}
var result *string
@@ -332,10 +284,6 @@ func renderToolDetails(
t := theme.CurrentTheme()
backgroundColor := t.BackgroundPanel()
borderColor := t.BackgroundPanel()
if highlight {
backgroundColor = t.BackgroundElement()
borderColor = t.BorderActive()
}
if toolCall.State.Metadata != nil {
metadata := toolCall.State.Metadata.(map[string]any)
@@ -370,9 +318,6 @@ func renderToolDetails(
Foreground(t.TextMuted()).
Padding(1, 2).
Width(width - 4)
if highlight {
style = style.Foreground(t.Text()).Bold(true)
}
if diagnostics := renderDiagnostics(metadata, filename); diagnostics != "" {
diagnostics = style.Render(diagnostics)
@@ -385,7 +330,6 @@ func renderToolDetails(
content = renderContentBlock(
app,
content,
highlight,
width,
WithPadding(0),
WithBorderColor(borderColor),
@@ -486,7 +430,7 @@ func renderToolDetails(
title := renderToolTitle(toolCall, width)
content := title + "\n\n" + body
return renderContentBlock(app, content, highlight, width, WithBorderColor(borderColor))
return renderContentBlock(app, content, width, WithBorderColor(borderColor))
}
func renderToolName(name string) string {