@@ -1,37 +1,82 @@
11package page
22
33import (
4+ "github.com/charmbracelet/bubbles/key"
45 tea "github.com/charmbracelet/bubbletea"
6+ "github.com/charmbracelet/lipgloss"
57 "github.com/kujtimiihoxha/opencode/internal/tui/components/logs"
68 "github.com/kujtimiihoxha/opencode/internal/tui/layout"
9+ "github.com/kujtimiihoxha/opencode/internal/tui/styles"
710)
811
912var LogsPage PageID = "logs"
1013
11−type logsPage struct {
12− table logs.TableComponent
13− details logs.DetailComponent
14+type LogPage interface {
15+ tea.Model
16+ layout.Sizeable
17+ layout.Bindings
1418}
15−
16−func (p *logsPage) Init() tea.Cmd {
17− return nil
19+type logsPage struct {
20+ width, height int
21+ table layout.Container
22+ details layout.Container
1823}
1924
2025func (p *logsPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
21− return p, nil
26+ switch msg := msg.(type) {
27+ case tea.WindowSizeMsg:
28+ p.width = msg.Width
29+ p.height = msg.Height
30+ p.table.SetSize(msg.Width, msg.Height/2)
31+ p.details.SetSize(msg.Width, msg.Height/2)
32+ }
33+
34+ var cmds []tea.Cmd
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...)
2243}
2344
2445func (p *logsPage) View() string {
25− return p.table.View() + "\n" + p.details.View()
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+
53+func (p *logsPage) BindingKeys() []key.Binding {
54+ return p.table.BindingKeys()
2655}
2756
28−func NewLogsPage() tea.Model {
29− return layout.NewBentoLayout(
30− layout.BentoPanes{
31− layout.BentoRightTopPane: logs.NewLogsTable(),
32− layout.BentoRightBottomPane: logs.NewLogsDetails(),
33− },
34− layout.WithBentoLayoutCurrentPane(layout.BentoRightTopPane),
35− layout.WithBentoLayoutRightTopHeightRatio(0.5),
57+// GetSize implements LogPage.
58+func (p *logsPage) GetSize() (int, int) {
59+ return p.width, p.height
60+}
61+
62+// SetSize implements LogPage.
63+func (p *logsPage) SetSize(width int, height int) {
64+ p.width = width
65+ p.height = height
66+ p.table.SetSize(width, height/2)
67+ p.details.SetSize(width, height/2)
68+}
69+
70+func (p *logsPage) Init() tea.Cmd {
71+ return tea.Batch(
72+ p.table.Init(),
73+ p.details.Init(),
3674 )
3775}
76+
77+func NewLogsPage() LogPage {
78+ return &logsPage{
79+ table: layout.NewContainer(logs.NewLogsTable(), layout.WithBorderAll(), layout.WithBorderColor(styles.ForgroundDim)),
80+ details: layout.NewContainer(logs.NewLogsDetails(), layout.WithBorderAll(), layout.WithBorderColor(styles.ForgroundDim)),
81+ }
82+}