chat.go 2.2 KB

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