landing.go

 1package model
 2
 3import (
 4	"cmp"
 5	"fmt"
 6
 7	"charm.land/lipgloss/v2"
 8	"github.com/charmbracelet/catwalk/pkg/catwalk"
 9	"github.com/charmbracelet/crush/internal/agent"
10	"github.com/charmbracelet/crush/internal/ui/common"
11	uv "github.com/charmbracelet/ultraviolet"
12	"golang.org/x/text/cases"
13	"golang.org/x/text/language"
14)
15
16func (m *UI) selectedLargeModel() *agent.Model {
17	if m.com.App.AgentCoordinator != nil {
18		model := m.com.App.AgentCoordinator.Model()
19		return &model
20	}
21	return nil
22}
23
24func (m *UI) landingView() string {
25	t := m.com.Styles
26	width := m.layout.main.Dx()
27	cwd := common.PrettyPath(t, m.com.Config().WorkingDir(), width)
28
29	parts := []string{
30		cwd,
31	}
32
33	model := m.selectedLargeModel()
34	if model != nil && model.CatwalkCfg.CanReason {
35		reasoningInfo := ""
36		providerConfig, ok := m.com.Config().Providers.Get(model.ModelCfg.Provider)
37		if ok {
38			switch providerConfig.Type {
39			case catwalk.TypeAnthropic:
40				if model.ModelCfg.Think {
41					reasoningInfo = "Thinking On"
42				} else {
43					reasoningInfo = "Thinking Off"
44				}
45			default:
46				formatter := cases.Title(language.English, cases.NoLower)
47				reasoningEffort := cmp.Or(model.ModelCfg.ReasoningEffort, model.CatwalkCfg.DefaultReasoningEffort)
48				reasoningInfo = formatter.String(fmt.Sprintf("Reasoning %s", reasoningEffort))
49			}
50			parts = append(parts, "", common.ModelInfo(t, model.CatwalkCfg.Name, reasoningInfo, nil, width))
51		}
52	}
53	infoSection := lipgloss.JoinVertical(lipgloss.Left, parts...)
54
55	_, remainingHeightArea := uv.SplitVertical(m.layout.main, uv.Fixed(lipgloss.Height(infoSection)+1))
56
57	mcpLspSectionWidth := min(30, (width-1)/2)
58
59	lspSection := m.lspInfo(t, mcpLspSectionWidth, remainingHeightArea.Dy())
60	mcpSection := m.mcpInfo(t, mcpLspSectionWidth, remainingHeightArea.Dy())
61
62	content := lipgloss.JoinHorizontal(lipgloss.Left, lspSection, " ", mcpSection)
63
64	return lipgloss.NewStyle().
65		Width(width).
66		Height(m.layout.main.Dy() - 1).
67		PaddingTop(1).
68		Render(
69			lipgloss.JoinVertical(lipgloss.Left, infoSection, "", content),
70		)
71}