diff --git a/CRUSH.md b/CRUSH.md index c308db631e006dd1c3834b6b470a02f4c41ff53b..06c9b99e593596029212b8d4d95024b310a2d003 100644 --- a/CRUSH.md +++ b/CRUSH.md @@ -4,7 +4,7 @@ - **Build**: `go build .` or `go run .` - **Test**: `task test` or `go test ./...` (run single test: `go test ./internal/llm/prompt -run TestGetContextFromPaths`) -- **Lint**: `task lint` (golangci-lint run) or `task lint-fix` (with --fix) +- **Lint**: `task lint-fix` - **Format**: `task fmt` (gofumpt -w .) - **Dev**: `task dev` (runs with profiling enabled) diff --git a/internal/tui/components/chat/header/header.go b/internal/tui/components/chat/header/header.go index 5d27cc14fdf341ea3f201876f80f7edd7f1ce328..4eac0c2444321a59c06d2e83d328fd1ea9e8512c 100644 --- a/internal/tui/components/chat/header/header.go +++ b/internal/tui/components/chat/header/header.go @@ -21,6 +21,7 @@ type Header interface { SetSession(session session.Session) tea.Cmd SetWidth(width int) tea.Cmd SetDetailsOpen(open bool) + ShowingDetails() bool } type header struct { @@ -137,3 +138,8 @@ func (h *header) SetWidth(width int) tea.Cmd { h.width = width return nil } + +// ShowingDetails implements Header. +func (h *header) ShowingDetails() bool { + return h.detailsOpen +} diff --git a/internal/tui/components/chat/sidebar/sidebar.go b/internal/tui/components/chat/sidebar/sidebar.go index c6b83d978b3b7043842c78e8801436f4bee1a98d..cf1fd12dff512475fa77f0cd9fb657646c0cc2fd 100644 --- a/internal/tui/components/chat/sidebar/sidebar.go +++ b/internal/tui/components/chat/sidebar/sidebar.go @@ -135,15 +135,26 @@ func (m *sidebarCmp) View() string { parts = append(parts, m.currentModelBlock(), ) - if m.session.ID != "" { - parts = append(parts, "", m.filesBlock()) + + // Check if we should use horizontal layout for sections + if m.compactMode && m.width > m.height { + // Horizontal layout for compact mode when width > height + sectionsContent := m.renderSectionsHorizontal() + if sectionsContent != "" { + parts = append(parts, "", sectionsContent) + } + } else { + // Vertical layout (default) + if m.session.ID != "" { + parts = append(parts, "", m.filesBlock()) + } + parts = append(parts, + "", + m.lspBlock(), + "", + m.mcpBlock(), + ) } - parts = append(parts, - "", - m.lspBlock(), - "", - m.mcpBlock(), - ) style := t.S().Base. Width(m.width). @@ -347,6 +358,255 @@ func (m *sidebarCmp) getDynamicLimits() (maxFiles, maxLSPs, maxMCPs int) { return maxFiles, maxLSPs, maxMCPs } +// renderSectionsHorizontal renders the files, LSPs, and MCPs sections horizontally +func (m *sidebarCmp) renderSectionsHorizontal() string { + // Calculate available width for each section + totalWidth := m.width - 4 // Account for padding and spacing + sectionWidth := min(50, totalWidth/3) + + // Get the sections content with limited height + var filesContent, lspContent, mcpContent string + + filesContent = m.filesBlockCompact(sectionWidth) + lspContent = m.lspBlockCompact(sectionWidth) + mcpContent = m.mcpBlockCompact(sectionWidth) + + return lipgloss.JoinHorizontal(lipgloss.Top, filesContent, " ", lspContent, " ", mcpContent) +} + +// filesBlockCompact renders the files block with limited width and height for horizontal layout +func (m *sidebarCmp) filesBlockCompact(maxWidth int) string { + t := styles.CurrentTheme() + + section := t.S().Subtle.Render("Modified Files") + + files := make([]SessionFile, 0) + m.files.Range(func(key, value any) bool { + file := value.(SessionFile) + files = append(files, file) + return true + }) + + if len(files) == 0 { + content := lipgloss.JoinVertical( + lipgloss.Left, + section, + "", + t.S().Base.Foreground(t.Border).Render("None"), + ) + return lipgloss.NewStyle().Width(maxWidth).Render(content) + } + + fileList := []string{section, ""} + sort.Slice(files, func(i, j int) bool { + return files[i].History.latestVersion.CreatedAt > files[j].History.latestVersion.CreatedAt + }) + + // Limit items for horizontal layout - use less space + maxItems := min(5, len(files)) + availableHeight := m.height - 8 // Reserve space for header and other content + if availableHeight > 0 { + maxItems = min(maxItems, availableHeight) + } + + filesShown := 0 + for _, file := range files { + if file.Additions == 0 && file.Deletions == 0 { + continue + } + if filesShown >= maxItems { + break + } + + var statusParts []string + if file.Additions > 0 { + statusParts = append(statusParts, t.S().Base.Foreground(t.Success).Render(fmt.Sprintf("+%d", file.Additions))) + } + if file.Deletions > 0 { + statusParts = append(statusParts, t.S().Base.Foreground(t.Error).Render(fmt.Sprintf("-%d", file.Deletions))) + } + + extraContent := strings.Join(statusParts, " ") + cwd := config.Get().WorkingDir() + string(os.PathSeparator) + filePath := file.FilePath + filePath = strings.TrimPrefix(filePath, cwd) + filePath = fsext.DirTrim(fsext.PrettyPath(filePath), 2) + filePath = ansi.Truncate(filePath, maxWidth-lipgloss.Width(extraContent)-2, "…") + + fileList = append(fileList, + core.Status( + core.StatusOpts{ + IconColor: t.FgMuted, + NoIcon: true, + Title: filePath, + ExtraContent: extraContent, + }, + maxWidth, + ), + ) + filesShown++ + } + + // Add "..." indicator if there are more files + totalFilesWithChanges := 0 + for _, file := range files { + if file.Additions > 0 || file.Deletions > 0 { + totalFilesWithChanges++ + } + } + if totalFilesWithChanges > maxItems { + fileList = append(fileList, t.S().Base.Foreground(t.FgMuted).Render("…")) + } + + content := lipgloss.JoinVertical(lipgloss.Left, fileList...) + return lipgloss.NewStyle().Width(maxWidth).Render(content) +} + +// lspBlockCompact renders the LSP block with limited width and height for horizontal layout +func (m *sidebarCmp) lspBlockCompact(maxWidth int) string { + t := styles.CurrentTheme() + + section := t.S().Subtle.Render("LSPs") + + lspList := []string{section, ""} + + lsp := config.Get().LSP.Sorted() + if len(lsp) == 0 { + content := lipgloss.JoinVertical( + lipgloss.Left, + section, + "", + t.S().Base.Foreground(t.Border).Render("None"), + ) + return lipgloss.NewStyle().Width(maxWidth).Render(content) + } + + // Limit items for horizontal layout + maxItems := min(5, len(lsp)) + availableHeight := m.height - 8 + if availableHeight > 0 { + maxItems = min(maxItems, availableHeight) + } + + for i, l := range lsp { + if i >= maxItems { + break + } + + iconColor := t.Success + if l.LSP.Disabled { + iconColor = t.FgMuted + } + + lspErrs := map[protocol.DiagnosticSeverity]int{ + protocol.SeverityError: 0, + protocol.SeverityWarning: 0, + protocol.SeverityHint: 0, + protocol.SeverityInformation: 0, + } + if client, ok := m.lspClients[l.Name]; ok { + for _, diagnostics := range client.GetDiagnostics() { + for _, diagnostic := range diagnostics { + if severity, ok := lspErrs[diagnostic.Severity]; ok { + lspErrs[diagnostic.Severity] = severity + 1 + } + } + } + } + + errs := []string{} + if lspErrs[protocol.SeverityError] > 0 { + errs = append(errs, t.S().Base.Foreground(t.Error).Render(fmt.Sprintf("%s %d", styles.ErrorIcon, lspErrs[protocol.SeverityError]))) + } + if lspErrs[protocol.SeverityWarning] > 0 { + errs = append(errs, t.S().Base.Foreground(t.Warning).Render(fmt.Sprintf("%s %d", styles.WarningIcon, lspErrs[protocol.SeverityWarning]))) + } + if lspErrs[protocol.SeverityHint] > 0 { + errs = append(errs, t.S().Base.Foreground(t.FgHalfMuted).Render(fmt.Sprintf("%s %d", styles.HintIcon, lspErrs[protocol.SeverityHint]))) + } + if lspErrs[protocol.SeverityInformation] > 0 { + errs = append(errs, t.S().Base.Foreground(t.FgHalfMuted).Render(fmt.Sprintf("%s %d", styles.InfoIcon, lspErrs[protocol.SeverityInformation]))) + } + + lspList = append(lspList, + core.Status( + core.StatusOpts{ + IconColor: iconColor, + Title: l.Name, + Description: l.LSP.Command, + ExtraContent: strings.Join(errs, " "), + }, + maxWidth, + ), + ) + } + + // Add "..." indicator if there are more LSPs + if len(lsp) > maxItems { + lspList = append(lspList, t.S().Base.Foreground(t.FgMuted).Render("…")) + } + + content := lipgloss.JoinVertical(lipgloss.Left, lspList...) + return lipgloss.NewStyle().Width(maxWidth).Render(content) +} + +// mcpBlockCompact renders the MCP block with limited width and height for horizontal layout +func (m *sidebarCmp) mcpBlockCompact(maxWidth int) string { + t := styles.CurrentTheme() + + section := t.S().Subtle.Render("MCPs") + + mcpList := []string{section, ""} + + mcps := config.Get().MCP.Sorted() + if len(mcps) == 0 { + content := lipgloss.JoinVertical( + lipgloss.Left, + section, + "", + t.S().Base.Foreground(t.Border).Render("None"), + ) + return lipgloss.NewStyle().Width(maxWidth).Render(content) + } + + // Limit items for horizontal layout + maxItems := min(5, len(mcps)) + availableHeight := m.height - 8 + if availableHeight > 0 { + maxItems = min(maxItems, availableHeight) + } + + for i, l := range mcps { + if i >= maxItems { + break + } + + iconColor := t.Success + if l.MCP.Disabled { + iconColor = t.FgMuted + } + + mcpList = append(mcpList, + core.Status( + core.StatusOpts{ + IconColor: iconColor, + Title: l.Name, + Description: l.MCP.Command, + }, + maxWidth, + ), + ) + } + + // Add "..." indicator if there are more MCPs + if len(mcps) > maxItems { + mcpList = append(mcpList, t.S().Base.Foreground(t.FgMuted).Render("…")) + } + + content := lipgloss.JoinVertical(lipgloss.Left, mcpList...) + return lipgloss.NewStyle().Width(maxWidth).Render(content) +} + func (m *sidebarCmp) filesBlock() string { t := styles.CurrentTheme() diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index 49b0ff4ecc49dce5da005a4b9912bf64598dae97..14e9b47b65608a04c3d295ae8b88fac1bec69873 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -315,6 +315,9 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (p *chatPage) Cursor() *tea.Cursor { + if p.header.ShowingDetails() { + return nil + } switch p.focusedPane { case PanelTypeEditor: return p.editor.Cursor()