.gitignore 🔗
@@ -41,7 +41,5 @@ Thumbs.db
.env
.env.local
-.opencode
+.opencode/
-internal/assets/diff/index.mjs
-cmd/test/*
Kujtim Hoxha created
.gitignore | 4 -
internal/tui/components/logs/details.go | 29 ---------
internal/tui/components/logs/table.go | 45 +++++++--------
internal/tui/page/logs.go | 77 +++++++++++++++++++++-----
4 files changed, 86 insertions(+), 69 deletions(-)
@@ -41,7 +41,5 @@ Thumbs.db
.env
.env.local
-.opencode
+.opencode/
-internal/assets/diff/index.mjs
-cmd/test/*
@@ -22,7 +22,6 @@ type DetailComponent interface {
type detailCmp struct {
width, height int
- focused bool
currentLog logging.LogMessage
viewport viewport.Model
}
@@ -37,11 +36,6 @@ func (i *detailCmp) Init() tea.Cmd {
}
func (i *detailCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
- var (
- cmd tea.Cmd
- cmds []tea.Cmd
- )
-
switch msg := msg.(type) {
case selectedLogMsg:
if msg.ID != i.currentLog.ID {
@@ -50,12 +44,7 @@ func (i *detailCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
- if i.focused {
- i.viewport, cmd = i.viewport.Update(msg)
- cmds = append(cmds, cmd)
- }
-
- return i, tea.Batch(cmds...)
+ return i, nil
}
func (i *detailCmp) updateContent() {
@@ -123,21 +112,7 @@ func getLevelStyle(level string) lipgloss.Style {
}
func (i *detailCmp) View() string {
- return i.viewport.View()
-}
-
-func (i *detailCmp) Blur() tea.Cmd {
- i.focused = false
- return nil
-}
-
-func (i *detailCmp) Focus() tea.Cmd {
- i.focused = true
- return nil
-}
-
-func (i *detailCmp) IsFocused() bool {
- return i.focused
+ return styles.ForceReplaceBackgroundWithLipgloss(i.viewport.View(), styles.Background)
}
func (i *detailCmp) GetSize() (int, int) {
@@ -33,37 +33,35 @@ func (i *tableCmp) Init() tea.Cmd {
func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmds []tea.Cmd
- if i.table.Focused() {
- switch msg.(type) {
- case pubsub.Event[logging.LogMessage]:
- i.setRows()
- return i, nil
- }
- prevSelectedRow := i.table.SelectedRow()
- t, cmd := i.table.Update(msg)
- cmds = append(cmds, cmd)
- i.table = t
- selectedRow := i.table.SelectedRow()
- if selectedRow != nil {
- if prevSelectedRow == nil || selectedRow[0] == prevSelectedRow[0] {
- var log logging.LogMessage
- for _, row := range logging.List() {
- if row.ID == selectedRow[0] {
- log = row
- break
- }
- }
- if log.ID != "" {
- cmds = append(cmds, util.CmdHandler(selectedLogMsg(log)))
+ switch msg.(type) {
+ case pubsub.Event[logging.LogMessage]:
+ i.setRows()
+ return i, nil
+ }
+ prevSelectedRow := i.table.SelectedRow()
+ t, cmd := i.table.Update(msg)
+ cmds = append(cmds, cmd)
+ i.table = t
+ selectedRow := i.table.SelectedRow()
+ if selectedRow != nil {
+ if prevSelectedRow == nil || selectedRow[0] == prevSelectedRow[0] {
+ var log logging.LogMessage
+ for _, row := range logging.List() {
+ if row.ID == selectedRow[0] {
+ log = row
+ break
}
}
+ if log.ID != "" {
+ cmds = append(cmds, util.CmdHandler(selectedLogMsg(log)))
+ }
}
}
return i, tea.Batch(cmds...)
}
func (i *tableCmp) View() string {
- return i.table.View()
+ return styles.ForceReplaceBackgroundWithLipgloss(i.table.View(), styles.Background)
}
func (i *tableCmp) GetSize() (int, int) {
@@ -128,6 +126,7 @@ func NewLogsTable() TableComponent {
table.WithColumns(columns),
table.WithStyles(defaultStyles),
)
+ tableModel.Focus()
return &tableCmp{
table: tableModel,
}
@@ -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)),
+ }
+}