SuperCoder/internal/tui/components/chat/chat.go

142 lines
2.7 KiB
Go
Raw Normal View History

2025-04-12 02:01:45 +02:00
package chat
import (
"fmt"
2025-04-19 15:15:29 +02:00
"sort"
2025-04-12 02:01:45 +02:00
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
2025-04-24 18:25:52 +02:00
"github.com/opencode-ai/opencode/internal/config"
2025-05-03 01:53:58 +05:30
"github.com/opencode-ai/opencode/internal/message"
2025-04-24 18:25:52 +02:00
"github.com/opencode-ai/opencode/internal/session"
"github.com/opencode-ai/opencode/internal/tui/styles"
"github.com/opencode-ai/opencode/internal/tui/theme"
2025-04-24 18:25:52 +02:00
"github.com/opencode-ai/opencode/internal/version"
2025-04-12 02:01:45 +02:00
)
type SendMsg struct {
2025-05-03 01:53:58 +05:30
Text string
Attachments []message.Attachment
2025-04-12 02:01:45 +02:00
}
type SessionSelectedMsg = session.Session
type SessionClearedMsg struct{}
type EditorFocusMsg bool
func header(width int) string {
return lipgloss.JoinVertical(
lipgloss.Top,
logo(width),
repo(width),
"",
cwd(width),
)
}
2025-04-12 02:01:45 +02:00
func lspsConfigured(width int) string {
cfg := config.Get()
title := "LSP Configuration"
title = ansi.Truncate(title, width, "…")
t := theme.CurrentTheme()
baseStyle := styles.BaseStyle()
lsps := baseStyle.
Width(width).
Foreground(t.Primary()).
Bold(true).
Render(title)
2025-04-12 02:01:45 +02:00
2025-04-19 15:15:29 +02:00
// Get LSP names and sort them for consistent ordering
var lspNames []string
for name := range cfg.LSP {
lspNames = append(lspNames, name)
}
sort.Strings(lspNames)
2025-04-12 02:01:45 +02:00
var lspViews []string
2025-04-19 15:15:29 +02:00
for _, name := range lspNames {
lsp := cfg.LSP[name]
lspName := baseStyle.
Foreground(t.Text()).
Render(fmt.Sprintf("• %s", name))
2025-04-12 02:01:45 +02:00
cmd := lsp.Command
cmd = ansi.Truncate(cmd, width-lipgloss.Width(lspName)-3, "…")
lspPath := baseStyle.
Foreground(t.TextMuted()).
Render(fmt.Sprintf(" (%s)", cmd))
2025-04-12 02:01:45 +02:00
lspViews = append(lspViews,
baseStyle.
2025-04-12 02:01:45 +02:00
Width(width).
Render(
lipgloss.JoinHorizontal(
lipgloss.Left,
lspName,
lspPath,
),
),
)
}
return baseStyle.
2025-04-12 02:01:45 +02:00
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()
2025-04-12 02:01:45 +02:00
versionText := baseStyle.
Foreground(t.TextMuted()).
Render(version.Version)
2025-04-12 02:01:45 +02:00
return baseStyle.
2025-04-12 02:01:45 +02:00
Bold(true).
Width(width).
Render(
lipgloss.JoinHorizontal(
lipgloss.Left,
logo,
" ",
versionText,
2025-04-12 02:01:45 +02:00
),
)
}
func repo(width int) string {
2025-04-24 18:25:52 +02:00
repo := "https://github.com/opencode-ai/opencode"
t := theme.CurrentTheme()
return styles.BaseStyle().
Foreground(t.TextMuted()).
2025-04-12 02:01:45 +02:00
Width(width).
Render(repo)
}
func cwd(width int) string {
cwd := fmt.Sprintf("cwd: %s", config.WorkingDirectory())
t := theme.CurrentTheme()
return styles.BaseStyle().
Foreground(t.TextMuted()).
2025-04-12 02:01:45 +02:00
Width(width).
Render(cwd)
}