on main help sign in
fix(tui): render a smaller logo on splash screen
7a282d3Ayman Bagabas
internal/tui/components/chat/sidebar/sidebar.go+11−21
@@ -114,12 +114,22 @@ func (m *sidebarCmp) View() string {
114 t := styles.CurrentTheme()
114 t := styles.CurrentTheme()
115 parts := []string{}
115 parts := []string{}
116
116
117+ style := t.S().Base.
118+ Width(m.width).
119+ Height(m.height).
120+ Padding(1)
121+ if m.compactMode {
122+ style = style.PaddingTop(0)
123+ }
124+
117 if !m.compactMode {
125 if !m.compactMode {
118 if m.height > LogoHeightBreakpoint {
126 if m.height > LogoHeightBreakpoint {
119 parts = append(parts, m.logo)
127 parts = append(parts, m.logo)
120 } else {
128 } else {
121 // Use a smaller logo for smaller screens
129 // Use a smaller logo for smaller screens
122− parts = append(parts, m.smallerScreenLogo(), "")
130+ parts = append(parts,
131+ logo.SmallRender(m.width-style.GetHorizontalFrameSize()),
132+ "")
123 }
133 }
124 }
134 }
125
135
@@ -159,13 +169,6 @@ func (m *sidebarCmp) View() string {
159 )
169 )
160 }
170 }
161
171
162− style := t.S().Base.
163− Width(m.width).
164− Height(m.height).
165− Padding(1)
166− if m.compactMode {
167− style = style.PaddingTop(0)
168− }
169 return style.Render(
172 return style.Render(
170 lipgloss.JoinVertical(lipgloss.Left, parts...),
173 lipgloss.JoinVertical(lipgloss.Left, parts...),
171 )
174 )
@@ -934,19 +937,6 @@ func (s *sidebarCmp) currentModelBlock() string {
934 )
937 )
935}
938}
936
939
937−func (m *sidebarCmp) smallerScreenLogo() string {
938− t := styles.CurrentTheme()
939− title := t.S().Base.Foreground(t.Secondary).Render("Charm™")
940− title += " " + styles.ApplyBoldForegroundGrad("CRUSH", t.Secondary, t.Primary)
941− remainingWidth := m.width - lipgloss.Width(title) - 3
942− if remainingWidth > 0 {
943− char := "╱"
944− lines := strings.Repeat(char, remainingWidth)
945− title += " " + t.S().Base.Foreground(t.Primary).Render(lines)
946− }
947− return title
948−}
949−
950// SetSession implements Sidebar.
940// SetSession implements Sidebar.
951func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
941func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
952 m.session = session
942 m.session = session
internal/tui/components/chat/splash/splash.go+15−6
@@ -134,10 +134,8 @@ func (s *splashCmp) Init() tea.Cmd {
134// SetSize implements SplashPage.
134// SetSize implements SplashPage.
135func (s *splashCmp) SetSize(width int, height int) tea.Cmd {
135func (s *splashCmp) SetSize(width int, height int) tea.Cmd {
136 s.height = height
136 s.height = height
137− if width != s.width {
137+ s.width = width
138− s.width = width
139− s.logoRendered = s.logoBlock()
138+ s.logoRendered = s.logoBlock()
140− }
141 // remove padding, logo height, gap, title space
139 // remove padding, logo height, gap, title space
142 s.listHeight = s.height - lipgloss.Height(s.logoRendered) - (SplashScreenPaddingY * 2) - s.logoGap() - 2
140 s.listHeight = s.height - lipgloss.Height(s.logoRendered) - (SplashScreenPaddingY * 2) - s.logoGap() - 2
143 listWidth := min(60, width)
141 listWidth := min(60, width)
@@ -467,14 +465,25 @@ func (s *splashCmp) infoSection() string {
467
465
468func (s *splashCmp) logoBlock() string {
466func (s *splashCmp) logoBlock() string {
469 t := styles.CurrentTheme()
467 t := styles.CurrentTheme()
470− return t.S().Base.Padding(0, 2).Width(s.width).Render(
468+ logoStyle := t.S().Base.Padding(0, 2).Width(s.width)
469+ if s.width < 40 || s.height < 20 {
470+ // If the width is too small, render a smaller version of the logo
471+ // NOTE: 20 is not correct because [splashCmp.height] is not the
472+ // *actual* window height, instead, it is the height of the splash
473+ // component and that depends on other variables like compact mode and
474+ // the height of the editor.
475+ return logoStyle.Render(
476+ logo.SmallRender(s.width - logoStyle.GetHorizontalFrameSize()),
477+ )
478+ }
479+ return logoStyle.Render(
471 logo.Render(version.Version, false, logo.Opts{
480 logo.Render(version.Version, false, logo.Opts{
472 FieldColor: t.Primary,
481 FieldColor: t.Primary,
473 TitleColorA: t.Secondary,
482 TitleColorA: t.Secondary,
474 TitleColorB: t.Primary,
483 TitleColorB: t.Primary,
475 CharmColor: t.Secondary,
484 CharmColor: t.Secondary,
476 VersionColor: t.Primary,
485 VersionColor: t.Primary,
477− Width: s.width - 4,
486+ Width: s.width - logoStyle.GetHorizontalFrameSize(),
478 }),
487 }),
479 )
488 )
480}
489}
internal/tui/components/logo/logo.go+14
@@ -110,6 +110,20 @@ func Render(version string, compact bool, o Opts) string {
110 return logo
110 return logo
111}
111}
112
112
113+// SmallRender renders a smaller version of the Crush logo, suitable for
114+// smaller windows or sidebar usage.
115+func SmallRender(width int) string {
116+ t := styles.CurrentTheme()
117+ title := t.S().Base.Foreground(t.Secondary).Render("Charm™")
118+ title = fmt.Sprintf("%s %s", title, styles.ApplyBoldForegroundGrad("Crush", t.Secondary, t.Primary))
119+ remainingWidth := width - lipgloss.Width(title) - 1 // 1 for the space after "Crush"
120+ if remainingWidth > 0 {
121+ lines := strings.Repeat("╱", remainingWidth)
122+ title = fmt.Sprintf("%s %s", title, t.S().Base.Foreground(t.Primary).Render(lines))
123+ }
124+ return title
125+}
126+
113// renderWord renders letterforms to fork a word.
127// renderWord renders letterforms to fork a word.
114func renderWord(spacing int, stretchRandomLetter bool, letterforms ...letterform) string {
128func renderWord(spacing int, stretchRandomLetter bool, letterforms ...letterform) string {
115 if spacing < 0 {
129 if spacing < 0 {