chat.go 2.2 KB

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