help.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package dialog
  2. import (
  3. tea "github.com/charmbracelet/bubbletea/v2"
  4. "github.com/sst/opencode/internal/app"
  5. commandsComponent "github.com/sst/opencode/internal/components/commands"
  6. "github.com/sst/opencode/internal/components/modal"
  7. "github.com/sst/opencode/internal/layout"
  8. "github.com/sst/opencode/internal/theme"
  9. )
  10. type helpDialog struct {
  11. width int
  12. height int
  13. modal *modal.Modal
  14. app *app.App
  15. commandsComponent commandsComponent.CommandsComponent
  16. }
  17. func (h *helpDialog) Init() tea.Cmd {
  18. return h.commandsComponent.Init()
  19. }
  20. func (h *helpDialog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
  21. switch msg := msg.(type) {
  22. case tea.WindowSizeMsg:
  23. h.width = msg.Width
  24. h.height = msg.Height
  25. h.commandsComponent.SetSize(msg.Width, msg.Height)
  26. }
  27. _, cmd := h.commandsComponent.Update(msg)
  28. return h, cmd
  29. }
  30. func (h *helpDialog) View() string {
  31. t := theme.CurrentTheme()
  32. h.commandsComponent.SetBackgroundColor(t.BackgroundElement())
  33. return h.commandsComponent.View()
  34. }
  35. func (h *helpDialog) Render(background string) string {
  36. return h.modal.Render(h.View(), background)
  37. }
  38. func (h *helpDialog) Close() tea.Cmd {
  39. return nil
  40. }
  41. type HelpDialog interface {
  42. layout.Modal
  43. }
  44. func NewHelpDialog(app *app.App) HelpDialog {
  45. return &helpDialog{
  46. app: app,
  47. commandsComponent: commandsComponent.New(app, commandsComponent.WithBackground(theme.CurrentTheme().BackgroundElement())),
  48. modal: modal.New(modal.WithTitle("Help")),
  49. }
  50. }