Browse Source

fix(tui): render attachments in user messages in accent color

adamdotdevin 7 tháng trước cách đây
mục cha
commit
a39136a2a0

+ 13 - 2
packages/tui/internal/components/chat/message.go

@@ -9,6 +9,7 @@ import (
 
 	"github.com/charmbracelet/lipgloss/v2"
 	"github.com/charmbracelet/lipgloss/v2/compat"
+	"github.com/charmbracelet/x/ansi"
 	"github.com/sst/opencode-sdk-go"
 	"github.com/sst/opencode/internal/app"
 	"github.com/sst/opencode/internal/components/diff"
@@ -193,8 +194,18 @@ func renderText(
 		content = util.ToMarkdown(text, width, backgroundColor)
 	case opencode.UserMessage:
 		ts = time.UnixMilli(int64(casted.Time.Created))
-		messageStyle := styles.NewStyle().Background(backgroundColor).Width(width - 6)
-		content = messageStyle.Render(text)
+		base := styles.NewStyle().Foreground(t.Text()).Background(backgroundColor)
+		words := strings.Fields(text)
+		for i, word := range words {
+			if strings.HasPrefix(word, "@") {
+				words[i] = base.Foreground(t.Secondary()).Render(word + " ")
+			} else {
+				words[i] = base.Render(word + " ")
+			}
+		}
+		text = strings.Join(words, "")
+		text = ansi.WordwrapWc(text, width-6, " -")
+		content = base.Width(width - 6).Render(text)
 	}
 
 	timestamp := ts.

+ 3 - 1
packages/tui/internal/tui/tui.go

@@ -1117,7 +1117,9 @@ func formatConversationToMarkdown(messages []app.Message) string {
 			continue
 		}
 
-		builder.WriteString(fmt.Sprintf("**%s** (*%s*)\n\n", role, timestamp.Format("2006-01-02 15:04:05")))
+		builder.WriteString(
+			fmt.Sprintf("**%s** (*%s*)\n\n", role, timestamp.Format("2006-01-02 15:04:05")),
+		)
 
 		for _, part := range msg.Parts {
 			switch p := part.(type) {