fix: use visual width instead of byte length for text truncation (#1562)

Gustave-241021 created

Change summary

internal/tui/components/chat/messages/renderer.go | 2 +-
internal/tui/components/chat/messages/tool.go     | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)

Detailed changes

internal/tui/components/chat/messages/renderer.go 🔗

@@ -1025,7 +1025,7 @@ func renderPlainContent(v *toolCallCmp, content string) string {
 		}
 		ln = ansiext.Escape(ln)
 		ln = " " + ln
-		if len(ln) > width {
+		if lipgloss.Width(ln) > width {
 			ln = v.fit(ln, width)
 		}
 		out = append(out, t.S().Muted.

internal/tui/components/chat/messages/tool.go 🔗

@@ -790,6 +790,9 @@ func (m *toolCallCmp) textWidth() int {
 
 // fit truncates content to fit within the specified width with ellipsis
 func (m *toolCallCmp) fit(content string, width int) string {
+	if lipgloss.Width(content) <= width {
+		return content
+	}
 	t := styles.CurrentTheme()
 	lineStyle := t.S().Muted
 	dots := lineStyle.Render("…")