chat.go

  1package chat
  2
  3import (
  4	"fmt"
  5
  6	"github.com/charmbracelet/lipgloss"
  7	"github.com/charmbracelet/x/ansi"
  8	"github.com/kujtimiihoxha/termai/internal/config"
  9	"github.com/kujtimiihoxha/termai/internal/session"
 10	"github.com/kujtimiihoxha/termai/internal/tui/styles"
 11	"github.com/kujtimiihoxha/termai/internal/version"
 12)
 13
 14type SendMsg struct {
 15	Text string
 16}
 17
 18type SessionSelectedMsg = session.Session
 19
 20type SessionClearedMsg struct{}
 21
 22type AgentWorkingMsg bool
 23
 24type EditorFocusMsg bool
 25
 26func lspsConfigured(width int) string {
 27	cfg := config.Get()
 28	title := "LSP Configuration"
 29	title = ansi.Truncate(title, width, "…")
 30
 31	lsps := styles.BaseStyle.Width(width).Foreground(styles.PrimaryColor).Bold(true).Render(title)
 32
 33	var lspViews []string
 34	for name, lsp := range cfg.LSP {
 35		lspName := styles.BaseStyle.Foreground(styles.Forground).Render(
 36			fmt.Sprintf("• %s", name),
 37		)
 38		cmd := lsp.Command
 39		cmd = ansi.Truncate(cmd, width-lipgloss.Width(lspName)-3, "…")
 40		lspPath := styles.BaseStyle.Foreground(styles.ForgroundDim).Render(
 41			fmt.Sprintf(" (%s)", cmd),
 42		)
 43		lspViews = append(lspViews,
 44			styles.BaseStyle.
 45				Width(width).
 46				Render(
 47					lipgloss.JoinHorizontal(
 48						lipgloss.Left,
 49						lspName,
 50						lspPath,
 51					),
 52				),
 53		)
 54
 55	}
 56	return styles.BaseStyle.
 57		Width(width).
 58		Render(
 59			lipgloss.JoinVertical(
 60				lipgloss.Left,
 61				lsps,
 62				lipgloss.JoinVertical(
 63					lipgloss.Left,
 64					lspViews...,
 65				),
 66			),
 67		)
 68}
 69
 70func logo(width int) string {
 71	logo := fmt.Sprintf("%s %s", styles.OpenCodeIcon, "OpenCode")
 72
 73	version := styles.BaseStyle.Foreground(styles.ForgroundDim).Render(version.Version)
 74
 75	return styles.BaseStyle.
 76		Bold(true).
 77		Width(width).
 78		Render(
 79			lipgloss.JoinHorizontal(
 80				lipgloss.Left,
 81				logo,
 82				" ",
 83				version,
 84			),
 85		)
 86}
 87
 88func repo(width int) string {
 89	repo := "https://github.com/kujtimiihoxha/opencode"
 90	return styles.BaseStyle.
 91		Foreground(styles.ForgroundDim).
 92		Width(width).
 93		Render(repo)
 94}
 95
 96func cwd(width int) string {
 97	cwd := fmt.Sprintf("cwd: %s", config.WorkingDirectory())
 98	return styles.BaseStyle.
 99		Foreground(styles.ForgroundDim).
100		Width(width).
101		Render(cwd)
102}
103
104func header(width int) string {
105	header := lipgloss.JoinVertical(
106		lipgloss.Top,
107		logo(width),
108		repo(width),
109		"",
110		cwd(width),
111	)
112	return header
113}