summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/components/chat/chat.go
blob: ad06728d3eccb5bc223ba9cf91e2aa2e38febbaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package chat

import (
	"fmt"
	"sort"

	"github.com/charmbracelet/lipgloss"
	"github.com/charmbracelet/x/ansi"
	"github.com/sst/opencode/internal/app"
	"github.com/sst/opencode/internal/styles"
	"github.com/sst/opencode/internal/theme"
)

type SendMsg struct {
	Text        string
	Attachments []app.Attachment
}

func header(app *app.App, width int) string {
	return lipgloss.JoinVertical(
		lipgloss.Top,
		logo(width),
		repo(width),
		"",
		cwd(app, width),
	)
}

func lspsConfigured(width int) string {
	// cfg := config.Get()
	title := "LSP Servers"
	title = ansi.Truncate(title, width, "…")

	t := theme.CurrentTheme()
	baseStyle := styles.BaseStyle()

	lsps := baseStyle.
		Width(width).
		Foreground(t.Primary()).
		Bold(true).
		Render(title)

	// Get LSP names and sort them for consistent ordering
	var lspNames []string
	// for name := range cfg.LSP {
	// 	lspNames = append(lspNames, name)
	// }
	sort.Strings(lspNames)

	var lspViews []string
	// for _, name := range lspNames {
	// lsp := cfg.LSP[name]
	// lspName := baseStyle.
	// 	Foreground(t.Text()).
	// 	Render(fmt.Sprintf("• %s", name))

	// cmd := lsp.Command
	// cmd = ansi.Truncate(cmd, width-lipgloss.Width(lspName)-3, "…")

	// lspPath := baseStyle.
	// 	Foreground(t.TextMuted()).
	// 	Render(fmt.Sprintf(" (%s)", cmd))

	// lspViews = append(lspViews,
	// 	baseStyle.
	// 		Width(width).
	// 		Render(
	// 			lipgloss.JoinHorizontal(
	// 				lipgloss.Left,
	// 				lspName,
	// 				lspPath,
	// 			),
	// 		),
	// )
	// }

	return baseStyle.
		Width(width).
		Render(
			lipgloss.JoinVertical(
				lipgloss.Left,
				lsps,
				lipgloss.JoinVertical(
					lipgloss.Left,
					lspViews...,
				),
			),
		)
}

func logo(width int) string {
	logo := fmt.Sprintf("%s %s", styles.OpenCodeIcon, "OpenCode")
	t := theme.CurrentTheme()
	baseStyle := styles.BaseStyle()

	versionText := baseStyle.
		Foreground(t.TextMuted()).
		Render("v0.0.1") // TODO: get version from server

	return baseStyle.
		Bold(true).
		Width(width).
		Render(
			lipgloss.JoinHorizontal(
				lipgloss.Left,
				logo,
				" ",
				versionText,
			),
		)
}

func repo(width int) string {
	repo := "github.com/sst/opencode"
	t := theme.CurrentTheme()

	return styles.BaseStyle().
		Foreground(t.TextMuted()).
		Width(width).
		Render(repo)
}

func cwd(app *app.App, width int) string {
	cwd := fmt.Sprintf("cwd: %s", app.Info.Path.Cwd)
	t := theme.CurrentTheme()

	return styles.BaseStyle().
		Foreground(t.TextMuted()).
		Width(width).
		Render(cwd)
}