From b8f74f33c52759625a1a5cd9f5f1a0b95675a781 Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Fri, 11 Jul 2025 16:35:27 +0200 Subject: [PATCH] chore: make the sidebar a bit more responsive --- .../tui/components/chat/sidebar/sidebar.go | 23 ++++++++++++++++++- internal/tui/page/chat/chat.go | 21 +++++++++-------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/internal/tui/components/chat/sidebar/sidebar.go b/internal/tui/components/chat/sidebar/sidebar.go index 3fa08ce021d0fcac1ce7dc9668d46198f6d08055..9bc77db5965c99eb8e365f140562c3b108aae63c 100644 --- a/internal/tui/components/chat/sidebar/sidebar.go +++ b/internal/tui/components/chat/sidebar/sidebar.go @@ -33,6 +33,8 @@ type FileHistory struct { latestVersion history.File } +const LogoHeightBreakpoint = 40 + type SessionFile struct { History FileHistory FilePath string @@ -100,8 +102,14 @@ func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m *sidebarCmp) View() string { t := styles.CurrentTheme() parts := []string{} + if !m.compactMode { - parts = append(parts, m.logo) + if m.height > LogoHeightBreakpoint { + parts = append(parts, m.logo) + } else { + // Use a smaller logo for smaller screens + parts = append(parts, m.smallerScreenLogo(), "") + } } if !m.compactMode && m.session.ID != "" { @@ -504,6 +512,19 @@ func (s *sidebarCmp) currentModelBlock() string { ) } +func (m *sidebarCmp) smallerScreenLogo() string { + t := styles.CurrentTheme() + title := t.S().Base.Foreground(t.Secondary).Render("Charm™") + title += " " + styles.ApplyBoldForegroundGrad("CRUSH", t.Secondary, t.Primary) + remainingWidth := m.width - lipgloss.Width(title) - 3 + if remainingWidth > 0 { + char := "╱" + lines := strings.Repeat(char, remainingWidth) + title += " " + t.S().Base.Foreground(t.Primary).Render(lines) + } + return title +} + // SetSession implements Sidebar. func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd { m.session = session diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index 33267772e96662f14934a8417149259c7d22541a..49b0ff4ecc49dce5da005a4b9912bf64598dae97 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -52,11 +52,12 @@ const ( ) const ( - CompactModeBreakpoint = 120 // Width at which the chat page switches to compact mode - EditorHeight = 5 // Height of the editor input area including padding - SideBarWidth = 31 // Width of the sidebar - SideBarDetailsPadding = 1 // Padding for the sidebar details section - HeaderHeight = 1 // Height of the header + CompactModeWidthBreakpoint = 120 // Width at which the chat page switches to compact mode + CompactModeHeightBreakpoint = 30 // Height at which the chat page switches to compact mode + EditorHeight = 5 // Height of the editor input area including padding + SideBarWidth = 31 // Width of the sidebar + SideBarDetailsPadding = 1 // Padding for the sidebar details section + HeaderHeight = 1 // Height of the header // Layout constants for borders and padding BorderWidth = 1 // Width of component borders @@ -178,7 +179,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if p.forceCompact { p.setCompactMode(true) cmd = p.updateCompactConfig(true) - } else if p.width >= CompactModeBreakpoint { + } else if p.width >= CompactModeWidthBreakpoint && p.height >= CompactModeHeightBreakpoint { p.setCompactMode(false) cmd = p.updateCompactConfig(false) } @@ -421,20 +422,20 @@ func (p *chatPage) setCompactMode(compact bool) { } } -func (p *chatPage) handleCompactMode(newWidth int) { +func (p *chatPage) handleCompactMode(newWidth int, newHeight int) { if p.forceCompact { return } - if newWidth < CompactModeBreakpoint && !p.compact { + if (newWidth < CompactModeWidthBreakpoint || newHeight < CompactModeHeightBreakpoint) && !p.compact { p.setCompactMode(true) } - if newWidth >= CompactModeBreakpoint && p.compact { + if (newWidth >= CompactModeWidthBreakpoint && newHeight >= CompactModeHeightBreakpoint) && p.compact { p.setCompactMode(false) } } func (p *chatPage) SetSize(width, height int) tea.Cmd { - p.handleCompactMode(width) + p.handleCompactMode(width, height) p.width = width p.height = height var cmds []tea.Cmd