|
1 | 1 | package page |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "github.com/charmbracelet/bubbles/key" |
4 | 5 | tea "github.com/charmbracelet/bubbletea" |
| 6 | + "github.com/charmbracelet/lipgloss" |
5 | 7 | "github.com/kujtimiihoxha/opencode/internal/tui/components/logs" |
6 | 8 | "github.com/kujtimiihoxha/opencode/internal/tui/layout" |
| 9 | + "github.com/kujtimiihoxha/opencode/internal/tui/styles" |
7 | 10 | ) |
8 | 11 |
|
9 | 12 | var LogsPage PageID = "logs" |
10 | 13 |
|
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 |
14 | 18 | } |
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 |
18 | 23 | } |
19 | 24 |
|
20 | 25 | func (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...) |
22 | 43 | } |
23 | 44 |
|
24 | 45 | func (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() |
26 | 55 | } |
27 | 56 |
|
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(), |
36 | 74 | ) |
37 | 75 | } |
| 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 | +} |
0 commit comments