@@ -193,30 +193,33 @@ func (m *messageCmp) renderAssistantMessage() string {
return m.style().Render(joined)
}
-// renderUserMessage renders user messages with file attachments.
-// Displays message content and any attached files with appropriate icons.
+// renderUserMessage renders user messages with file attachments. It displays
+// message content and any attached files with appropriate icons.
func (m *messageCmp) renderUserMessage() string {
t := styles.CurrentTheme()
parts := []string{
m.toMarkdown(m.message.Content().String()),
}
+
attachmentStyles := t.S().Text.
MarginLeft(1).
Background(t.BgSubtle)
- attachments := []string{}
- for _, attachment := range m.message.BinaryContent() {
- file := filepath.Base(attachment.Path)
- var filename string
- if len(file) > 10 {
- filename = fmt.Sprintf(" %s %s... ", styles.DocumentIcon, file[0:7])
- } else {
- filename = fmt.Sprintf(" %s %s ", styles.DocumentIcon, file)
- }
- attachments = append(attachments, attachmentStyles.Render(filename))
+
+ attachments := make([]string, len(m.message.BinaryContent()))
+ for i, attachment := range m.message.BinaryContent() {
+ const maxFilenameWidth = 10
+ filename := filepath.Base(attachment.Path)
+ attachments[i] = attachmentStyles.Render(fmt.Sprintf(
+ " %s %s ",
+ styles.DocumentIcon,
+ ansi.Truncate(filename, maxFilenameWidth, "..."),
+ ))
}
+
if len(attachments) > 0 {
parts = append(parts, "", strings.Join(attachments, ""))
}
+
joined := lipgloss.JoinVertical(lipgloss.Left, parts...)
return m.style().Render(joined)
}