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 EditorFocusMsg bool
 23
 24func lspsConfigured(width int) string {
 25	cfg := config.Get()
 26	title := "LSP Configuration"
 27	title = ansi.Truncate(title, width, "…")
 28
 29	lsps := styles.BaseStyle.Width(width).Foreground(styles.PrimaryColor).Bold(true).Render(title)
 30
 31	var lspViews []string
 32	for name, lsp := range cfg.LSP {
 33		lspName := styles.BaseStyle.Foreground(styles.Forground).Render(
 34			fmt.Sprintf("• %s", name),
 35		)
 36		cmd := lsp.Command
 37		cmd = ansi.Truncate(cmd, width-lipgloss.Width(lspName)-3, "…")
 38		lspPath := styles.BaseStyle.Foreground(styles.ForgroundDim).Render(
 39			fmt.Sprintf(" (%s)", cmd),
 40		)
 41		lspViews = append(lspViews,
 42			styles.BaseStyle.
 43				Width(width).
 44				Render(
 45					lipgloss.JoinHorizontal(
 46						lipgloss.Left,
 47						lspName,
 48						lspPath,
 49					),
 50				),
 51		)
 52
 53	}
 54	return styles.BaseStyle.
 55		Width(width).
 56		Render(
 57			lipgloss.JoinVertical(
 58				lipgloss.Left,
 59				lsps,
 60				lipgloss.JoinVertical(
 61					lipgloss.Left,
 62					lspViews...,
 63				),
 64			),
 65		)
 66}
 67
 68func logo(width int) string {
 69	logo := fmt.Sprintf("%s %s", styles.OpenCodeIcon, "OpenCode")
 70
 71	version := styles.BaseStyle.Foreground(styles.ForgroundDim).Render(version.Version)
 72
 73	return styles.BaseStyle.
 74		Bold(true).
 75		Width(width).
 76		Render(
 77			lipgloss.JoinHorizontal(
 78				lipgloss.Left,
 79				logo,
 80				" ",
 81				version,
 82			),
 83		)
 84}
 85
 86func repo(width int) string {
 87	repo := "https://github.com/kujtimiihoxha/opencode"
 88	return styles.BaseStyle.
 89		Foreground(styles.ForgroundDim).
 90		Width(width).
 91		Render(repo)
 92}
 93
 94func cwd(width int) string {
 95	cwd := fmt.Sprintf("cwd: %s", config.WorkingDirectory())
 96	return styles.BaseStyle.
 97		Foreground(styles.ForgroundDim).
 98		Width(width).
 99		Render(cwd)
100}
101
102func header(width int) string {
103	header := lipgloss.JoinVertical(
104		lipgloss.Top,
105		logo(width),
106		repo(width),
107		"",
108		cwd(width),
109	)
110	return header
111}