@@ -33,6 +33,16 @@ type FileHistory struct {
3333 latestVersion history.File
3434}
3535
36+const LogoHeightBreakpoint = 40
37+
38+// Default maximum number of items to show in each section
39+const (
40+ DefaultMaxFilesShown = 10
41+ DefaultMaxLSPsShown = 8
42+ DefaultMaxMCPsShown = 8
43+ MinItemsPerSection = 2 // Minimum items to show per section
44+)
45+
3646type SessionFile struct {
3747 History FileHistory
3848 FilePath string
@@ -100,8 +110,14 @@ func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
100110func (m *sidebarCmp) View() string {
101111 t := styles.CurrentTheme()
102112 parts := []string{}
113+
103114 if !m.compactMode {
104− parts = append(parts, m.logo)
115+ if m.height > LogoHeightBreakpoint {
116+ parts = append(parts, m.logo)
117+ } else {
118+ // Use a smaller logo for smaller screens
119+ parts = append(parts, m.smallerScreenLogo(), "")
120+ }
105121 }
106122
107123 if !m.compactMode && m.session.ID != "" {
@@ -119,15 +135,26 @@ func (m *sidebarCmp) View() string {
119135 parts = append(parts,
120136 m.currentModelBlock(),
121137 )
122− if m.session.ID != "" {
123− parts = append(parts, "", m.filesBlock())
138+
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)
145+ }
146+ } else {
147+ // Vertical layout (default)
148+ if m.session.ID != "" {
149+ parts = append(parts, "", m.filesBlock())
150+ }
151+ parts = append(parts,
152+ "",
153+ m.lspBlock(),
154+ "",
155+ m.mcpBlock(),
156+ )
124157 }
125− parts = append(parts,
126− "",
127− m.lspBlock(),
128− "",
129− m.mcpBlock(),
130− )
131158
132159 style := t.S().Base.
133160 Width(m.width).
@@ -258,6 +285,328 @@ func (m *sidebarCmp) getMaxWidth() int {
258285 return min(m.width-2, 58) // -2 for padding
259286}
260287
288+// calculateAvailableHeight estimates how much height is available for dynamic content
289+func (m *sidebarCmp) calculateAvailableHeight() int {
290+ usedHeight := 0
291+
292+ if !m.compactMode {
293+ if m.height > LogoHeightBreakpoint {
294+ usedHeight += 7 // Approximate logo height
295+ } else {
296+ usedHeight += 2 // Smaller logo height
297+ }
298+ usedHeight += 1 // Empty line after logo
299+ }
300+
301+ if m.session.ID != "" {
302+ usedHeight += 1 // Title line
303+ usedHeight += 1 // Empty line after title
304+ }
305+
306+ if !m.compactMode {
307+ usedHeight += 1 // CWD line
308+ usedHeight += 1 // Empty line after CWD
309+ }
310+
311+ usedHeight += 2 // Model info
312+
313+ usedHeight += 6 // 3 sections × 2 lines each (header + empty line)
314+
315+ // Base padding
316+ usedHeight += 2 // Top and bottom padding
317+
318+ return max(0, m.height-usedHeight)
319+}
320+
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()
324+
325+ // If we have very little space, use minimum values
326+ if availableHeight < 10 {
327+ return MinItemsPerSection, MinItemsPerSection, MinItemsPerSection
328+ }
329+
330+ // Distribute available height among the three sections
331+ // Give priority to files, then LSPs, then MCPs
332+ totalSections := 3
333+ heightPerSection := availableHeight / totalSections
334+
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))
339+
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
346+
347+ if remainingHeight > 0 {
348+ extraForLSPs := min(remainingHeight, DefaultMaxLSPsShown-maxLSPs)
349+ maxLSPs += extraForLSPs
350+ remainingHeight -= extraForLSPs
351+
352+ if remainingHeight > 0 {
353+ maxMCPs += min(remainingHeight, DefaultMaxMCPsShown-maxMCPs)
354+ }
355+ }
356+ }
357+
358+ return maxFiles, maxLSPs, maxMCPs
359+}
360+
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)
366+
367+ // Get the sections content with limited height
368+ var filesContent, lspContent, mcpContent string
369+
370+ filesContent = m.filesBlockCompact(sectionWidth)
371+ lspContent = m.lspBlockCompact(sectionWidth)
372+ mcpContent = m.mcpBlockCompact(sectionWidth)
373+
374+ return lipgloss.JoinHorizontal(lipgloss.Top, filesContent, " ", lspContent, " ", mcpContent)
375+}
376+
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()
380+
381+ section := t.S().Subtle.Render("Modified Files")
382+
383+ files := make([]SessionFile, 0)
384+ m.files.Range(func(key, value any) bool {
385+ file := value.(SessionFile)
386+ files = append(files, file)
387+ return true
388+ })
389+
390+ if len(files) == 0 {
391+ content := lipgloss.JoinVertical(
392+ lipgloss.Left,
393+ section,
394+ "",
395+ t.S().Base.Foreground(t.Border).Render("None"),
396+ )
397+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
398+ }
399+
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
403+ })
404+
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)
410+ }
411+
412+ filesShown := 0
413+ for _, file := range files {
414+ if file.Additions == 0 && file.Deletions == 0 {
415+ continue
416+ }
417+ if filesShown >= maxItems {
418+ break
419+ }
420+
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)))
424+ }
425+ if file.Deletions > 0 {
426+ statusParts = append(statusParts, t.S().Base.Foreground(t.Error).Render(fmt.Sprintf("-%d", file.Deletions)))
427+ }
428+
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, "…")
435+
436+ fileList = append(fileList,
437+ core.Status(
438+ core.StatusOpts{
439+ IconColor: t.FgMuted,
440+ NoIcon: true,
441+ Title: filePath,
442+ ExtraContent: extraContent,
443+ },
444+ maxWidth,
445+ ),
446+ )
447+ filesShown++
448+ }
449+
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++
455+ }
456+ }
457+ if totalFilesWithChanges > maxItems {
458+ fileList = append(fileList, t.S().Base.Foreground(t.FgMuted).Render("…"))
459+ }
460+
461+ content := lipgloss.JoinVertical(lipgloss.Left, fileList...)
462+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
463+}
464+
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()
468+
469+ section := t.S().Subtle.Render("LSPs")
470+
471+ lspList := []string{section, ""}
472+
473+ lsp := config.Get().LSP.Sorted()
474+ if len(lsp) == 0 {
475+ content := lipgloss.JoinVertical(
476+ lipgloss.Left,
477+ section,
478+ "",
479+ t.S().Base.Foreground(t.Border).Render("None"),
480+ )
481+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
482+ }
483+
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)
489+ }
490+
491+ for i, l := range lsp {
492+ if i >= maxItems {
493+ break
494+ }
495+
496+ iconColor := t.Success
497+ if l.LSP.Disabled {
498+ iconColor = t.FgMuted
499+ }
500+
501+ lspErrs := map[protocol.DiagnosticSeverity]int{
502+ protocol.SeverityError: 0,
503+ protocol.SeverityWarning: 0,
504+ protocol.SeverityHint: 0,
505+ protocol.SeverityInformation: 0,
506+ }
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
512+ }
513+ }
514+ }
515+ }
516+
517+ errs := []string{}
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])))
520+ }
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])))
523+ }
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])))
526+ }
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])))
529+ }
530+
531+ lspList = append(lspList,
532+ core.Status(
533+ core.StatusOpts{
534+ IconColor: iconColor,
535+ Title: l.Name,
536+ Description: l.LSP.Command,
537+ ExtraContent: strings.Join(errs, " "),
538+ },
539+ maxWidth,
540+ ),
541+ )
542+ }
543+
544+ // Add "..." indicator if there are more LSPs
545+ if len(lsp) > maxItems {
546+ lspList = append(lspList, t.S().Base.Foreground(t.FgMuted).Render("…"))
547+ }
548+
549+ content := lipgloss.JoinVertical(lipgloss.Left, lspList...)
550+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
551+}
552+
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()
556+
557+ section := t.S().Subtle.Render("MCPs")
558+
559+ mcpList := []string{section, ""}
560+
561+ mcps := config.Get().MCP.Sorted()
562+ if len(mcps) == 0 {
563+ content := lipgloss.JoinVertical(
564+ lipgloss.Left,
565+ section,
566+ "",
567+ t.S().Base.Foreground(t.Border).Render("None"),
568+ )
569+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
570+ }
571+
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)
577+ }
578+
579+ for i, l := range mcps {
580+ if i >= maxItems {
581+ break
582+ }
583+
584+ iconColor := t.Success
585+ if l.MCP.Disabled {
586+ iconColor = t.FgMuted
587+ }
588+
589+ mcpList = append(mcpList,
590+ core.Status(
591+ core.StatusOpts{
592+ IconColor: iconColor,
593+ Title: l.Name,
594+ Description: l.MCP.Command,
595+ },
596+ maxWidth,
597+ ),
598+ )
599+ }
600+
601+ // Add "..." indicator if there are more MCPs
602+ if len(mcps) > maxItems {
603+ mcpList = append(mcpList, t.S().Base.Foreground(t.FgMuted).Render("…"))
604+ }
605+
606+ content := lipgloss.JoinVertical(lipgloss.Left, mcpList...)
607+ return lipgloss.NewStyle().Width(maxWidth).Render(content)
608+}
609+
261610func (m *sidebarCmp) filesBlock() string {
262611 t := styles.CurrentTheme()
263612
@@ -286,10 +635,19 @@ func (m *sidebarCmp) filesBlock() string {
286635 return files[i].History.latestVersion.CreatedAt > files[j].History.latestVersion.CreatedAt
287636 })
288637
638+ // Limit the number of files shown
639+ maxFiles, _, _ := m.getDynamicLimits()
640+ maxFiles = min(len(files), maxFiles)
641+ filesShown := 0
642+
289643 for _, file := range files {
290644 if file.Additions == 0 && file.Deletions == 0 {
291645 continue // skip files with no changes
292646 }
647+ if filesShown >= maxFiles {
648+ break
649+ }
650+
293651 var statusParts []string
294652 if file.Additions > 0 {
295653 statusParts = append(statusParts, t.S().Base.Foreground(t.Success).Render(fmt.Sprintf("+%d", file.Additions)))
@@ -315,6 +673,21 @@ func (m *sidebarCmp) filesBlock() string {
315673 m.getMaxWidth(),
316674 ),
317675 )
676+ filesShown++
677+ }
678+
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++
684+ }
685+ }
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)),
690+ )
318691 }
319692
320693 return lipgloss.JoinVertical(
@@ -342,7 +715,14 @@ func (m *sidebarCmp) lspBlock() string {
342715 )
343716 }
344717
345− for _, l := range lsp {
718+ // Limit the number of LSPs shown
719+ _, maxLSPs, _ := m.getDynamicLimits()
720+ maxLSPs = min(len(lsp), maxLSPs)
721+ for i, l := range lsp {
722+ if i >= maxLSPs {
723+ break
724+ }
725+
346726 iconColor := t.Success
347727 if l.LSP.Disabled {
348728 iconColor = t.FgMuted
@@ -390,6 +770,14 @@ func (m *sidebarCmp) lspBlock() string {
390770 )
391771 }
392772
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)),
778+ )
779+ }
780+
393781 return lipgloss.JoinVertical(
394782 lipgloss.Left,
395783 lspList...,
@@ -415,7 +803,14 @@ func (m *sidebarCmp) mcpBlock() string {
415803 )
416804 }
417805
418− for _, l := range mcps {
806+ // Limit the number of MCPs shown
807+ _, _, maxMCPs := m.getDynamicLimits()
808+ maxMCPs = min(len(mcps), maxMCPs)
809+ for i, l := range mcps {
810+ if i >= maxMCPs {
811+ break
812+ }
813+
419814 iconColor := t.Success
420815 if l.MCP.Disabled {
421816 iconColor = t.FgMuted
@@ -432,6 +827,14 @@ func (m *sidebarCmp) mcpBlock() string {
432827 )
433828 }
434829
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)),
835+ )
836+ }
837+
435838 return lipgloss.JoinVertical(
436839 lipgloss.Left,
437840 mcpList...,
@@ -504,6 +907,19 @@ func (s *sidebarCmp) currentModelBlock() string {
504907 )
505908}
506909
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 {
916+ char := "╱"
917+ lines := strings.Repeat(char, remainingWidth)
918+ title += " " + t.S().Base.Foreground(t.Primary).Render(lines)
919+ }
920+ return title
921+}
922+
507923// SetSession implements Sidebar.
508924func (m *sidebarCmp) SetSession(session session.Session) tea.Cmd {
509925 m.session = session