@@ -33,6 +33,16 @@ type FileHistory struct {
33 latestVersion history.File
33 latestVersion history.File
36+const LogoHeightBreakpoint = 40
38+// Default maximum number of items to show in each section
40+ DefaultMaxFilesShown = 10
41+ DefaultMaxLSPsShown = 8
42+ DefaultMaxMCPsShown = 8
43+ MinItemsPerSection = 2 // Minimum items to show per section
36type SessionFile struct {
46type SessionFile struct {
37 History FileHistory
47 History FileHistory
38 FilePath string
48 FilePath string
@@ -100,8 +110,14 @@ func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
100func (m *sidebarCmp) View() string {
110func (m *sidebarCmp) View() string {
101 t := styles.CurrentTheme()
111 t := styles.CurrentTheme()
102 parts := []string{}
112 parts := []string{}
103 if !m.compactMode {
114 if !m.compactMode {
115+ if m.height > LogoHeightBreakpoint {
104− parts = append(parts, m.logo)
116+ parts = append(parts, m.logo)
118+ // Use a smaller logo for smaller screens
119+ parts = append(parts, m.smallerScreenLogo(), "")
107 if !m.compactMode && m.session.ID != "" {
123 if !m.compactMode && m.session.ID != "" {
@@ -119,15 +135,26 @@ func (m *sidebarCmp) View() string {
119 parts = append(parts,
135 parts = append(parts,
120 m.currentModelBlock(),
136 m.currentModelBlock(),
139+ // Check if we should use horizontal layout for sections
140+ if m.compactMode && m.width > m.height {
141+ // Horizontal layout for compact mode when width > height
142+ sectionsContent := m.renderSectionsHorizontal()
143+ if sectionsContent != "" {
144+ parts = append(parts, "", sectionsContent)
147+ // Vertical layout (default)
122− if m.session.ID != "" {
148+ if m.session.ID != "" {
123− parts = append(parts, "", m.filesBlock())
149+ parts = append(parts, "", m.filesBlock())
151+ parts = append(parts,
125− parts = append(parts,
132 style := t.S().Base.
159 style := t.S().Base.
133 Width(m.width).
160 Width(m.width).
@@ -258,6 +285,328 @@ func (m *sidebarCmp) getMaxWidth() int {
258 return min(m.width-2, 58) // -2 for padding
285 return min(m.width-2, 58) // -2 for padding
288+// calculateAvailableHeight estimates how much height is available for dynamic content
289+func (m *sidebarCmp) calculateAvailableHeight() int {
293+ if m.height > LogoHeightBreakpoint {
294+ usedHeight += 7 // Approximate logo height
296+ usedHeight += 2 // Smaller logo height
298+ usedHeight += 1 // Empty line after logo
301+ if m.session.ID != "" {
302+ usedHeight += 1 // Title line
303+ usedHeight += 1 // Empty line after title
307+ usedHeight += 1 // CWD line
308+ usedHeight += 1 // Empty line after CWD
311+ usedHeight += 2 // Model info
313+ usedHeight += 6 // 3 sections × 2 lines each (header + empty line)
316+ usedHeight += 2 // Top and bottom padding
318+ return max(0, m.height-usedHeight)
321+// getDynamicLimits calculates how many items to show in each section based on available height
322+func (m *sidebarCmp) getDynamicLimits() (maxFiles, maxLSPs, maxMCPs int) {
323+ availableHeight := m.calculateAvailableHeight()
325+ // If we have very little space, use minimum values
326+ if availableHeight < 10 {
327+ return MinItemsPerSection, MinItemsPerSection, MinItemsPerSection
330+ // Distribute available height among the three sections
331+ // Give priority to files, then LSPs, then MCPs
333+ heightPerSection := availableHeight / totalSections
335+ // Calculate limits for each section, ensuring minimums
336+ maxFiles = max(MinItemsPerSection, min(DefaultMaxFilesShown, heightPerSection))
337+ maxLSPs = max(MinItemsPerSection, min(DefaultMaxLSPsShown, heightPerSection))
338+ maxMCPs = max(MinItemsPerSection, min(DefaultMaxMCPsShown, heightPerSection))
340+ // If we have extra space, give it to files first
341+ remainingHeight := availableHeight - (maxFiles + maxLSPs + maxMCPs)
342+ if remainingHeight > 0 {
343+ extraForFiles := min(remainingHeight, DefaultMaxFilesShown-maxFiles)
344+ maxFiles += extraForFiles
345+ remainingHeight -= extraForFiles
347+ if remainingHeight > 0 {
348+ extraForLSPs := min(remainingHeight, DefaultMaxLSPsShown-maxLSPs)
349+ maxLSPs += extraForLSPs
350+ remainingHeight -= extraForLSPs
352+ if remainingHeight > 0 {
353+ maxMCPs += min(remainingHeight, DefaultMaxMCPsShown-maxMCPs)
358+ return maxFiles, maxLSPs, maxMCPs
361+// renderSectionsHorizontal renders the files, LSPs, and MCPs sections horizontally
362+func (m *sidebarCmp) renderSectionsHorizontal() string {
363+ // Calculate available width for each section
364+ totalWidth := m.width - 4 // Account for padding and spacing
365+ sectionWidth := min(50, totalWidth/3)
367+ // Get the sections content with limited height
368+ var filesContent, lspContent, mcpContent string
370+ filesContent = m.filesBlockCompact(sectionWidth)
371+ lspContent = m.lspBlockCompact(sectionWidth)
372+ mcpContent = m.mcpBlockCompact(sectionWidth)
374+ return lipgloss.JoinHorizontal(lipgloss.Top, filesContent, " ", lspContent, " ", mcpContent)
377+// filesBlockCompact renders the files block with limited width and height for horizontal layout
378+func (m *sidebarCmp) filesBlockCompact(maxWidth int) string {
379+ t := styles.CurrentTheme()
381+ section := t.S().Subtle.Render("Modified Files")
383+ files := make([]SessionFile, 0)
384+ m.files.Range(func(key, value any) bool {
385+ file := value.(SessionFile)
386+ files = append(files, file)
390+ if len(files) == 0 {
391+ content := lipgloss.JoinVertical(
395+ t.S().Base.Foreground(t.Border).Render("None"),
397+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
400+ fileList := []string{section, ""}
401+ sort.Slice(files, func(i, j int) bool {
402+ return files[i].History.latestVersion.CreatedAt > files[j].History.latestVersion.CreatedAt
405+ // Limit items for horizontal layout - use less space
406+ maxItems := min(5, len(files))
407+ availableHeight := m.height - 8 // Reserve space for header and other content
408+ if availableHeight > 0 {
409+ maxItems = min(maxItems, availableHeight)
413+ for _, file := range files {
414+ if file.Additions == 0 && file.Deletions == 0 {
417+ if filesShown >= maxItems {
421+ var statusParts []string
422+ if file.Additions > 0 {
423+ statusParts = append(statusParts, t.S().Base.Foreground(t.Success).Render(fmt.Sprintf("+%d", file.Additions)))
425+ if file.Deletions > 0 {
426+ statusParts = append(statusParts, t.S().Base.Foreground(t.Error).Render(fmt.Sprintf("-%d", file.Deletions)))
429+ extraContent := strings.Join(statusParts, " ")
430+ cwd := config.Get().WorkingDir() + string(os.PathSeparator)
431+ filePath := file.FilePath
432+ filePath = strings.TrimPrefix(filePath, cwd)
433+ filePath = fsext.DirTrim(fsext.PrettyPath(filePath), 2)
434+ filePath = ansi.Truncate(filePath, maxWidth-lipgloss.Width(extraContent)-2, "…")
436+ fileList = append(fileList,
439+ IconColor: t.FgMuted,
442+ ExtraContent: extraContent,
450+ // Add "..." indicator if there are more files
451+ totalFilesWithChanges := 0
452+ for _, file := range files {
453+ if file.Additions > 0 || file.Deletions > 0 {
454+ totalFilesWithChanges++
457+ if totalFilesWithChanges > maxItems {
458+ fileList = append(fileList, t.S().Base.Foreground(t.FgMuted).Render("…"))
461+ content := lipgloss.JoinVertical(lipgloss.Left, fileList...)
462+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
465+// lspBlockCompact renders the LSP block with limited width and height for horizontal layout
466+func (m *sidebarCmp) lspBlockCompact(maxWidth int) string {
467+ t := styles.CurrentTheme()
469+ section := t.S().Subtle.Render("LSPs")
471+ lspList := []string{section, ""}
473+ lsp := config.Get().LSP.Sorted()
475+ content := lipgloss.JoinVertical(
479+ t.S().Base.Foreground(t.Border).Render("None"),
481+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
484+ // Limit items for horizontal layout
485+ maxItems := min(5, len(lsp))
486+ availableHeight := m.height - 8
487+ if availableHeight > 0 {
488+ maxItems = min(maxItems, availableHeight)
491+ for i, l := range lsp {
496+ iconColor := t.Success
498+ iconColor = t.FgMuted
501+ lspErrs := map[protocol.DiagnosticSeverity]int{
502+ protocol.SeverityError: 0,
503+ protocol.SeverityWarning: 0,
504+ protocol.SeverityHint: 0,
505+ protocol.SeverityInformation: 0,
507+ if client, ok := m.lspClients[l.Name]; ok {
508+ for _, diagnostics := range client.GetDiagnostics() {
509+ for _, diagnostic := range diagnostics {
510+ if severity, ok := lspErrs[diagnostic.Severity]; ok {
511+ lspErrs[diagnostic.Severity] = severity + 1
518+ if lspErrs[protocol.SeverityError] > 0 {
519+ errs = append(errs, t.S().Base.Foreground(t.Error).Render(fmt.Sprintf("%s %d", styles.ErrorIcon, lspErrs[protocol.SeverityError])))
521+ if lspErrs[protocol.SeverityWarning] > 0 {
522+ errs = append(errs, t.S().Base.Foreground(t.Warning).Render(fmt.Sprintf("%s %d", styles.WarningIcon, lspErrs[protocol.SeverityWarning])))
524+ if lspErrs[protocol.SeverityHint] > 0 {
525+ errs = append(errs, t.S().Base.Foreground(t.FgHalfMuted).Render(fmt.Sprintf("%s %d", styles.HintIcon, lspErrs[protocol.SeverityHint])))
527+ if lspErrs[protocol.SeverityInformation] > 0 {
528+ errs = append(errs, t.S().Base.Foreground(t.FgHalfMuted).Render(fmt.Sprintf("%s %d", styles.InfoIcon, lspErrs[protocol.SeverityInformation])))
531+ lspList = append(lspList,
534+ IconColor: iconColor,
536+ Description: l.LSP.Command,
537+ ExtraContent: strings.Join(errs, " "),
544+ // Add "..." indicator if there are more LSPs
545+ if len(lsp) > maxItems {
546+ lspList = append(lspList, t.S().Base.Foreground(t.FgMuted).Render("…"))
549+ content := lipgloss.JoinVertical(lipgloss.Left, lspList...)
550+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
553+// mcpBlockCompact renders the MCP block with limited width and height for horizontal layout
554+func (m *sidebarCmp) mcpBlockCompact(maxWidth int) string {
555+ t := styles.CurrentTheme()
557+ section := t.S().Subtle.Render("MCPs")
559+ mcpList := []string{section, ""}
561+ mcps := config.Get().MCP.Sorted()
563+ content := lipgloss.JoinVertical(
567+ t.S().Base.Foreground(t.Border).Render("None"),
569+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
572+ // Limit items for horizontal layout
573+ maxItems := min(5, len(mcps))
574+ availableHeight := m.height - 8
575+ if availableHeight > 0 {
576+ maxItems = min(maxItems, availableHeight)
579+ for i, l := range mcps {
584+ iconColor := t.Success
586+ iconColor = t.FgMuted
589+ mcpList = append(mcpList,
592+ IconColor: iconColor,
594+ Description: l.MCP.Command,
601+ // Add "..." indicator if there are more MCPs
602+ if len(mcps) > maxItems {
603+ mcpList = append(mcpList, t.S().Base.Foreground(t.FgMuted).Render("…"))
606+ content := lipgloss.JoinVertical(lipgloss.Left, mcpList...)
607+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
261func (m *sidebarCmp) filesBlock() string {
610func (m *sidebarCmp) filesBlock() string {
262 t := styles.CurrentTheme()
611 t := styles.CurrentTheme()
@@ -286,10 +635,19 @@ func (m *sidebarCmp) filesBlock() string {
286 return files[i].History.latestVersion.CreatedAt > files[j].History.latestVersion.CreatedAt
635 return files[i].History.latestVersion.CreatedAt > files[j].History.latestVersion.CreatedAt
638+ // Limit the number of files shown
639+ maxFiles, _, _ := m.getDynamicLimits()
640+ maxFiles = min(len(files), maxFiles)
289 for _, file := range files {
643 for _, file := range files {
290 if file.Additions == 0 && file.Deletions == 0 {
644 if file.Additions == 0 && file.Deletions == 0 {
291 continue // skip files with no changes
645 continue // skip files with no changes
647+ if filesShown >= maxFiles {
293 var statusParts []string
651 var statusParts []string
294 if file.Additions > 0 {
652 if file.Additions > 0 {
295 statusParts = append(statusParts, t.S().Base.Foreground(t.Success).Render(fmt.Sprintf("+%d", file.Additions)))
653 statusParts = append(statusParts, t.S().Base.Foreground(t.Success).Render(fmt.Sprintf("+%d", file.Additions)))
@@ -315,6 +673,21 @@ func (m *sidebarCmp) filesBlock() string {
315 m.getMaxWidth(),
673 m.getMaxWidth(),
679+ // Add indicator if there are more files
680+ totalFilesWithChanges := 0
681+ for _, file := range files {
682+ if file.Additions > 0 || file.Deletions > 0 {
683+ totalFilesWithChanges++
686+ if totalFilesWithChanges > maxFiles {
687+ remaining := totalFilesWithChanges - maxFiles
688+ fileList = append(fileList,
689+ t.S().Base.Foreground(t.FgMuted).Render(fmt.Sprintf("… and %d more", remaining)),
320 return lipgloss.JoinVertical(
693 return lipgloss.JoinVertical(
@@ -342,7 +715,14 @@ func (m *sidebarCmp) lspBlock() string {
718+ // Limit the number of LSPs shown
719+ _, maxLSPs, _ := m.getDynamicLimits()
720+ maxLSPs = min(len(lsp), maxLSPs)
345− for _, l := range lsp {
721+ for i, l := range lsp {
346 iconColor := t.Success
726 iconColor := t.Success
347 if l.LSP.Disabled {
727 if l.LSP.Disabled {
348 iconColor = t.FgMuted
728 iconColor = t.FgMuted
@@ -390,6 +770,14 @@ func (m *sidebarCmp) lspBlock() string {
773+ // Add indicator if there are more LSPs
774+ if len(lsp) > maxLSPs {
775+ remaining := len(lsp) - maxLSPs
776+ lspList = append(lspList,
777+ t.S().Base.Foreground(t.FgMuted).Render(fmt.Sprintf("… and %d more", remaining)),
393 return lipgloss.JoinVertical(
781 return lipgloss.JoinVertical(
394 lipgloss.Left,
782 lipgloss.Left,
395 lspList...,
783 lspList...,
@@ -415,7 +803,14 @@ func (m *sidebarCmp) mcpBlock() string {
806+ // Limit the number of MCPs shown
807+ _, _, maxMCPs := m.getDynamicLimits()
808+ maxMCPs = min(len(mcps), maxMCPs)
418− for _, l := range mcps {
809+ for i, l := range mcps {
419 iconColor := t.Success
814 iconColor := t.Success
420 if l.MCP.Disabled {
815 if l.MCP.Disabled {
421 iconColor = t.FgMuted
816 iconColor = t.FgMuted
@@ -432,6 +827,14 @@ func (m *sidebarCmp) mcpBlock() string {
830+ // Add indicator if there are more MCPs
831+ if len(mcps) > maxMCPs {
832+ remaining := len(mcps) - maxMCPs
833+ mcpList = append(mcpList,
834+ t.S().Base.Foreground(t.FgMuted).Render(fmt.Sprintf("… and %d more", remaining)),
435 return lipgloss.JoinVertical(
838 return lipgloss.JoinVertical(
436 lipgloss.Left,
839 lipgloss.Left,
437 mcpList...,
840 mcpList...,
@@ -504,6 +907,19 @@ func (s *sidebarCmp) currentModelBlock() string {
910+func (m *sidebarCmp) smallerScreenLogo() string {
911+ t := styles.CurrentTheme()
912+ title := t.S().Base.Foreground(t.Secondary).Render("Charm™")
913+ title += " " + styles.ApplyBoldForegroundGrad("CRUSH", t.Secondary, t.Primary)
914+ remainingWidth := m.width - lipgloss.Width(title) - 3
915+ if remainingWidth > 0 {
917+ lines := strings.Repeat(char, remainingWidth)
918+ title += " " + t.S().Base.Foreground(t.Primary).Render(lines)
507// SetSession implements Sidebar.
923// SetSession implements Sidebar.
508func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
924func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
509 m.session = session
925 m.session = session