|
|
@@ -1,37 +1,82 @@
|
|
|
package page
|
|
|
|
|
|
import (
|
|
|
+ "github.com/charmbracelet/bubbles/key"
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
+ "github.com/charmbracelet/lipgloss"
|
|
|
"github.com/kujtimiihoxha/opencode/internal/tui/components/logs"
|
|
|
"github.com/kujtimiihoxha/opencode/internal/tui/layout"
|
|
|
+ "github.com/kujtimiihoxha/opencode/internal/tui/styles"
|
|
|
)
|
|
|
|
|
|
var LogsPage PageID = "logs"
|
|
|
|
|
|
-type logsPage struct {
|
|
|
- table logs.TableComponent
|
|
|
- details logs.DetailComponent
|
|
|
+type LogPage interface {
|
|
|
+ tea.Model
|
|
|
+ layout.Sizeable
|
|
|
+ layout.Bindings
|
|
|
}
|
|
|
-
|
|
|
-func (p *logsPage) Init() tea.Cmd {
|
|
|
- return nil
|
|
|
+type logsPage struct {
|
|
|
+ width, height int
|
|
|
+ table layout.Container
|
|
|
+ details layout.Container
|
|
|
}
|
|
|
|
|
|
func (p *logsPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
- return p, nil
|
|
|
+ switch msg := msg.(type) {
|
|
|
+ case tea.WindowSizeMsg:
|
|
|
+ p.width = msg.Width
|
|
|
+ p.height = msg.Height
|
|
|
+ p.table.SetSize(msg.Width, msg.Height/2)
|
|
|
+ p.details.SetSize(msg.Width, msg.Height/2)
|
|
|
+ }
|
|
|
+
|
|
|
+ var cmds []tea.Cmd
|
|
|
+ table, cmd := p.table.Update(msg)
|
|
|
+ cmds = append(cmds, cmd)
|
|
|
+ p.table = table.(layout.Container)
|
|
|
+ details, cmd := p.details.Update(msg)
|
|
|
+ cmds = append(cmds, cmd)
|
|
|
+ p.details = details.(layout.Container)
|
|
|
+
|
|
|
+ return p, tea.Batch(cmds...)
|
|
|
}
|
|
|
|
|
|
func (p *logsPage) View() string {
|
|
|
- return p.table.View() + "\n" + p.details.View()
|
|
|
+ style := styles.BaseStyle.Width(p.width).Height(p.height)
|
|
|
+ return style.Render(lipgloss.JoinVertical(lipgloss.Top,
|
|
|
+ p.table.View(),
|
|
|
+ p.details.View(),
|
|
|
+ ))
|
|
|
+}
|
|
|
+
|
|
|
+func (p *logsPage) BindingKeys() []key.Binding {
|
|
|
+ return p.table.BindingKeys()
|
|
|
}
|
|
|
|
|
|
-func NewLogsPage() tea.Model {
|
|
|
- return layout.NewBentoLayout(
|
|
|
- layout.BentoPanes{
|
|
|
- layout.BentoRightTopPane: logs.NewLogsTable(),
|
|
|
- layout.BentoRightBottomPane: logs.NewLogsDetails(),
|
|
|
- },
|
|
|
- layout.WithBentoLayoutCurrentPane(layout.BentoRightTopPane),
|
|
|
- layout.WithBentoLayoutRightTopHeightRatio(0.5),
|
|
|
+// GetSize implements LogPage.
|
|
|
+func (p *logsPage) GetSize() (int, int) {
|
|
|
+ return p.width, p.height
|
|
|
+}
|
|
|
+
|
|
|
+// SetSize implements LogPage.
|
|
|
+func (p *logsPage) SetSize(width int, height int) {
|
|
|
+ p.width = width
|
|
|
+ p.height = height
|
|
|
+ p.table.SetSize(width, height/2)
|
|
|
+ p.details.SetSize(width, height/2)
|
|
|
+}
|
|
|
+
|
|
|
+func (p *logsPage) Init() tea.Cmd {
|
|
|
+ return tea.Batch(
|
|
|
+ p.table.Init(),
|
|
|
+ p.details.Init(),
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
+func NewLogsPage() LogPage {
|
|
|
+ return &logsPage{
|
|
|
+ table: layout.NewContainer(logs.NewLogsTable(), layout.WithBorderAll(), layout.WithBorderColor(styles.ForgroundDim)),
|
|
|
+ details: layout.NewContainer(logs.NewLogsDetails(), layout.WithBorderAll(), layout.WithBorderColor(styles.ForgroundDim)),
|
|
|
+ }
|
|
|
+}
|