@@ -207,18 +207,27 @@ func (m *messageCmp) renderUserMessage() string {
208 attachments := make([]string, len(m.message.BinaryContent()))
208 attachments := make([]string, len(m.message.BinaryContent()))
209 for i, attachment := range m.message.BinaryContent() {
209 for i, attachment := range m.message.BinaryContent() {
210− file := filepath.Base(attachment.Path)
210+ filename := filepath.Base(attachment.Path)
211− var filename string
211+ var displayFilename string
212− runes := []rune(file)
212+ runes := []rune(filename)
214− const truncatePathAt = 7
214+ const truncateAtChars = 7
215− if len(runes) > truncatePathAt {
215+ const truncateSuffix = "..."
217+ // If the filename is too long, truncate it to fit within the maximum
218+ // width we’ve chosen.
219+ if lipgloss.Width(filename) > truncateAtChars+lipgloss.Width(truncateSuffix) {
220+ displayFilename = fmt.Sprintf(
216− filename = fmt.Sprintf(" %s %s... ", styles.DocumentIcon, string(runes[0:truncatePathAt]))
222+ styles.DocumentIcon,
223+ string(runes[0:truncateAtChars]),
218− filename = fmt.Sprintf(" %s %s ", styles.DocumentIcon, file)
227+ displayFilename = fmt.Sprintf(" %s %s ", styles.DocumentIcon, filename)
221− attachments[i] = attachmentStyles.Render(filename)
230+ attachments[i] = attachmentStyles.Render(displayFilename)
224 if len(attachments) > 0 {
233 if len(attachments) > 0 {