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