1package chat
2
3import (
4 "fmt"
5 "sort"
6
7 "github.com/charmbracelet/lipgloss/v2"
8 "github.com/opencode-ai/opencode/internal/config"
9 "github.com/opencode-ai/opencode/internal/message"
10 "github.com/opencode-ai/opencode/internal/session"
11 "github.com/opencode-ai/opencode/internal/tui/components/logo"
12 "github.com/opencode-ai/opencode/internal/tui/styles"
13 "github.com/opencode-ai/opencode/internal/tui/theme"
14 "github.com/opencode-ai/opencode/internal/version"
15)
16
17type SendMsg struct {
18 Text string
19 Attachments []message.Attachment
20}
21
22type SessionSelectedMsg = session.Session
23
24type SessionClearedMsg struct{}
25
26type EditorFocusMsg bool
27
28func header() string {
29 return lipgloss.JoinVertical(
30 lipgloss.Top,
31 logoBlock(),
32 repo(),
33 "",
34 cwd(),
35 )
36}
37
38func lspsConfigured() string {
39 cfg := config.Get()
40 title := "LSP Configuration"
41
42 t := theme.CurrentTheme()
43 baseStyle := styles.BaseStyle()
44
45 lsps := baseStyle.
46 Foreground(t.Primary()).
47 Bold(true).
48 Render(title)
49
50 // Get LSP names and sort them for consistent ordering
51 var lspNames []string
52 for name := range cfg.LSP {
53 lspNames = append(lspNames, name)
54 }
55 sort.Strings(lspNames)
56
57 var lspViews []string
58 for _, name := range lspNames {
59 lsp := cfg.LSP[name]
60 lspName := baseStyle.
61 Foreground(t.Text()).
62 Render(fmt.Sprintf("• %s", name))
63
64 cmd := lsp.Command
65
66 lspPath := baseStyle.
67 Foreground(t.TextMuted()).
68 Render(fmt.Sprintf(" (%s)", cmd))
69
70 lspViews = append(lspViews,
71 baseStyle.
72 Render(
73 lipgloss.JoinHorizontal(
74 lipgloss.Left,
75 lspName,
76 lspPath,
77 ),
78 ),
79 )
80 }
81
82 return baseStyle.
83 Render(
84 lipgloss.JoinVertical(
85 lipgloss.Left,
86 lsps,
87 lipgloss.JoinVertical(
88 lipgloss.Left,
89 lspViews...,
90 ),
91 ),
92 )
93}
94
95func logoBlock() string {
96 t := theme.CurrentTheme()
97 return logo.Render(version.Version, true, logo.Opts{
98 FieldColor: t.Secondary(),
99 TitleColorA: t.Primary(),
100 TitleColorB: t.Secondary(),
101 CharmColor: t.Primary(),
102 VersionColor: t.Secondary(),
103 })
104}
105
106func repo() string {
107 repo := "https://github.com/opencode-ai/opencode"
108 t := theme.CurrentTheme()
109
110 return styles.BaseStyle().
111 Foreground(t.TextMuted()).
112 Render(repo)
113}
114
115func cwd() string {
116 cwd := fmt.Sprintf("cwd: %s", config.WorkingDirectory())
117 t := theme.CurrentTheme()
118
119 return styles.BaseStyle().
120 Foreground(t.TextMuted()).
121 Render(cwd)
122}
123
124func initialScreen() string {
125 baseStyle := styles.BaseStyle()
126
127 return baseStyle.Render(
128 lipgloss.JoinVertical(
129 lipgloss.Top,
130 header(),
131 "",
132 lspsConfigured(),
133 ),
134 )
135}