chat.go 2.4 KB

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