logs.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package page
  2. import (
  3. "github.com/charmbracelet/bubbles/key"
  4. tea "github.com/charmbracelet/bubbletea"
  5. "github.com/charmbracelet/lipgloss"
  6. "github.com/opencode-ai/opencode/internal/tui/components/logs"
  7. "github.com/opencode-ai/opencode/internal/tui/layout"
  8. "github.com/opencode-ai/opencode/internal/tui/styles"
  9. )
  10. var LogsPage PageID = "logs"
  11. type LogPage interface {
  12. tea.Model
  13. layout.Sizeable
  14. layout.Bindings
  15. }
  16. type logsPage struct {
  17. width, height int
  18. table layout.Container
  19. details layout.Container
  20. }
  21. func (p *logsPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
  22. var cmds []tea.Cmd
  23. switch msg := msg.(type) {
  24. case tea.WindowSizeMsg:
  25. p.width = msg.Width
  26. p.height = msg.Height
  27. return p, p.SetSize(msg.Width, msg.Height)
  28. }
  29. table, cmd := p.table.Update(msg)
  30. cmds = append(cmds, cmd)
  31. p.table = table.(layout.Container)
  32. details, cmd := p.details.Update(msg)
  33. cmds = append(cmds, cmd)
  34. p.details = details.(layout.Container)
  35. return p, tea.Batch(cmds...)
  36. }
  37. func (p *logsPage) View() string {
  38. style := styles.BaseStyle().Width(p.width).Height(p.height)
  39. return style.Render(lipgloss.JoinVertical(lipgloss.Top,
  40. p.table.View(),
  41. p.details.View(),
  42. ))
  43. }
  44. func (p *logsPage) BindingKeys() []key.Binding {
  45. return p.table.BindingKeys()
  46. }
  47. // GetSize implements LogPage.
  48. func (p *logsPage) GetSize() (int, int) {
  49. return p.width, p.height
  50. }
  51. // SetSize implements LogPage.
  52. func (p *logsPage) SetSize(width int, height int) tea.Cmd {
  53. p.width = width
  54. p.height = height
  55. return tea.Batch(
  56. p.table.SetSize(width, height/2),
  57. p.details.SetSize(width, height/2),
  58. )
  59. }
  60. func (p *logsPage) Init() tea.Cmd {
  61. return tea.Batch(
  62. p.table.Init(),
  63. p.details.Init(),
  64. )
  65. }
  66. func NewLogsPage() LogPage {
  67. return &logsPage{
  68. table: layout.NewContainer(logs.NewLogsTable(), layout.WithBorderAll()),
  69. details: layout.NewContainer(logs.NewLogsDetails(), layout.WithBorderAll()),
  70. }
  71. }