chat.go

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