chat.go 2.4 KB

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