chat.go 2.4 KB

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