Merge pull request #127 from charmbracelet/truncate-logo

Kujtim Hoxha created

fix(tui): logo: make sure we truncate the logo if it exceeds the width

Change summary

internal/tui/components/chat/sidebar/sidebar.go |  1 +
internal/tui/components/logo/logo.go            | 11 ++++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)

Detailed changes

internal/tui/components/logo/logo.go 🔗

@@ -98,7 +98,16 @@ func Render(version string, compact bool, o Opts) string {
 
 	// Return the wide version.
 	const hGap = " "
-	return lipgloss.JoinHorizontal(lipgloss.Top, leftField.String(), hGap, crush, hGap, rightField.String())
+	logo := lipgloss.JoinHorizontal(lipgloss.Top, leftField.String(), hGap, crush, hGap, rightField.String())
+	if o.Width > 0 {
+		// Truncate the logo to the specified width.
+		lines := strings.Split(logo, "\n")
+		for i, line := range lines {
+			lines[i] = ansi.Truncate(line, o.Width, "")
+		}
+		logo = strings.Join(lines, "\n")
+	}
+	return logo
 }
 
 // renderWord renders letterforms to fork a word.