on main help sign in
chore: make the sidebar a bit more responsive
b8f74f3Kujtim Hoxha
internal/tui/components/chat/sidebar/sidebar.go+22−1
@@ -33,6 +33,8 @@ type FileHistory struct {
33 latestVersion history.File
33 latestVersion history.File
34}
34}
35
35
36+const LogoHeightBreakpoint = 40
37+
36type SessionFile struct {
38type SessionFile struct {
37 History FileHistory
39 History FileHistory
38 FilePath string
40 FilePath string
@@ -100,8 +102,14 @@ func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
100func (m *sidebarCmp) View() string {
102func (m *sidebarCmp) View() string {
101 t := styles.CurrentTheme()
103 t := styles.CurrentTheme()
102 parts := []string{}
104 parts := []string{}
105+
103 if !m.compactMode {
106 if !m.compactMode {
107+ if m.height > LogoHeightBreakpoint {
104− parts = append(parts, m.logo)
108+ parts = append(parts, m.logo)
109+ } else {
110+ // Use a smaller logo for smaller screens
111+ parts = append(parts, m.smallerScreenLogo(), "")
112+ }
105 }
113 }
106
114
107 if !m.compactMode && m.session.ID != "" {
115 if !m.compactMode && m.session.ID != "" {
@@ -504,6 +512,19 @@ func (s *sidebarCmp) currentModelBlock() string {
504 )
512 )
505}
513}
506
514
515+func (m *sidebarCmp) smallerScreenLogo() string {
516+ t := styles.CurrentTheme()
517+ title := t.S().Base.Foreground(t.Secondary).Render("Charm™")
518+ title += " " + styles.ApplyBoldForegroundGrad("CRUSH", t.Secondary, t.Primary)
519+ remainingWidth := m.width - lipgloss.Width(title) - 3
520+ if remainingWidth > 0 {
521+ char := "╱"
522+ lines := strings.Repeat(char, remainingWidth)
523+ title += " " + t.S().Base.Foreground(t.Primary).Render(lines)
524+ }
525+ return title
526+}
527+
507// SetSession implements Sidebar.
528// SetSession implements Sidebar.
508func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
529func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
509 m.session = session
530 m.session = session
internal/tui/page/chat/chat.go+11−10
@@ -52,11 +52,12 @@ const (
52)
52)
53
53
54const (
54const (
55− CompactModeBreakpoint = 120 // Width at which the chat page switches to compact mode
55+ CompactModeWidthBreakpoint = 120 // Width at which the chat page switches to compact mode
56+ CompactModeHeightBreakpoint = 30 // Height at which the chat page switches to compact mode
56− EditorHeight = 5 // Height of the editor input area including padding
57+ EditorHeight = 5 // Height of the editor input area including padding
57− SideBarWidth = 31 // Width of the sidebar
58+ SideBarWidth = 31 // Width of the sidebar
58− SideBarDetailsPadding = 1 // Padding for the sidebar details section
59+ SideBarDetailsPadding = 1 // Padding for the sidebar details section
59− HeaderHeight = 1 // Height of the header
60+ HeaderHeight = 1 // Height of the header
60
61
61 // Layout constants for borders and padding
62 // Layout constants for borders and padding
62 BorderWidth = 1 // Width of component borders
63 BorderWidth = 1 // Width of component borders
@@ -178,7 +179,7 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
178 if p.forceCompact {
179 if p.forceCompact {
179 p.setCompactMode(true)
180 p.setCompactMode(true)
180 cmd = p.updateCompactConfig(true)
181 cmd = p.updateCompactConfig(true)
181− } else if p.width >= CompactModeBreakpoint {
182+ } else if p.width >= CompactModeWidthBreakpoint && p.height >= CompactModeHeightBreakpoint {
182 p.setCompactMode(false)
183 p.setCompactMode(false)
183 cmd = p.updateCompactConfig(false)
184 cmd = p.updateCompactConfig(false)
184 }
185 }
@@ -421,20 +422,20 @@ func (p *chatPage) setCompactMode(compact bool) {
421 }
422 }
422}
423}
423
424
424−func (p *chatPage) handleCompactMode(newWidth int) {
425+func (p *chatPage) handleCompactMode(newWidth int, newHeight int) {
425 if p.forceCompact {
426 if p.forceCompact {
426 return
427 return
427 }
428 }
428− if newWidth < CompactModeBreakpoint && !p.compact {
429+ if (newWidth < CompactModeWidthBreakpoint || newHeight < CompactModeHeightBreakpoint) && !p.compact {
429 p.setCompactMode(true)
430 p.setCompactMode(true)
430 }
431 }
431− if newWidth >= CompactModeBreakpoint && p.compact {
432+ if (newWidth >= CompactModeWidthBreakpoint && newHeight >= CompactModeHeightBreakpoint) && p.compact {
432 p.setCompactMode(false)
433 p.setCompactMode(false)
433 }
434 }
434}
435}
435
436
436func (p *chatPage) SetSize(width, height int) tea.Cmd {
437func (p *chatPage) SetSize(width, height int) tea.Cmd {
437− p.handleCompactMode(width)
438+ p.handleCompactMode(width, height)
438 p.width = width
439 p.width = width
439 p.height = height
440 p.height = height
440 var cmds []tea.Cmd
441 var cmds []tea.Cmd