on main help sign in
update logs
commit05d0e86f10369fd0e51a924ac88029fb92591499 authorKujtim Hoxha <kujtimii.h@gmail.com> dateThu 17 Apr 2025, 16:03 (2 years ago) parente3a6273
4 files changed+86−69
.gitignore+1−3 internal/tui/components/logs/details.go+2−27 internal/tui/components/logs/table.go+22−23 internal/tui/page/logs.go+61−16
.gitignore+1−3
@@ -41,7 +41,5 @@ Thumbs.db
4141.env
4242.env.local
4343
44−.opencode
44+.opencode/
4545
46−internal/assets/diff/index.mjs
47−cmd/test/*
internal/tui/components/logs/details.go+2−27
@@ -22,7 +22,6 @@ type DetailComponent interface {
2222
2323type detailCmp struct {
2424 width, height int
25− focused bool
2625 currentLog logging.LogMessage
2726 viewport viewport.Model
2827}
@@ -37,11 +36,6 @@ func (i *detailCmp) Init() tea.Cmd {
3736}
3837
3938func (i *detailCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
40− var (
41− cmd tea.Cmd
42− cmds []tea.Cmd
43− )
44−
4539 switch msg := msg.(type) {
4640 case selectedLogMsg:
4741 if msg.ID != i.currentLog.ID {
@@ -50,12 +44,7 @@ func (i *detailCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5044 }
5145 }
5246
53− if i.focused {
54− i.viewport, cmd = i.viewport.Update(msg)
55− cmds = append(cmds, cmd)
56− }
57−
58− return i, tea.Batch(cmds...)
47+ return i, nil
5948}
6049
6150func (i *detailCmp) updateContent() {
@@ -123,21 +112,7 @@ func getLevelStyle(level string) lipgloss.Style {
123112}
124113
125114func (i *detailCmp) View() string {
126− return i.viewport.View()
127−}
128−
129−func (i *detailCmp) Blur() tea.Cmd {
130− i.focused = false
131− return nil
132−}
133−
134−func (i *detailCmp) Focus() tea.Cmd {
135− i.focused = true
136− return nil
137−}
138−
139−func (i *detailCmp) IsFocused() bool {
140− return i.focused
115+ return styles.ForceReplaceBackgroundWithLipgloss(i.viewport.View(), styles.Background)
141116}
142117
143118func (i *detailCmp) GetSize() (int, int) {
internal/tui/components/logs/table.go+22−23
@@ -33,37 +33,35 @@ func (i *tableCmp) Init() tea.Cmd {
3333
3434func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
3535 var cmds []tea.Cmd
36− if i.table.Focused() {
37− switch msg.(type) {
38− case pubsub.Event[logging.LogMessage]:
39− i.setRows()
40− return i, nil
41− }
42− prevSelectedRow := i.table.SelectedRow()
43− t, cmd := i.table.Update(msg)
44− cmds = append(cmds, cmd)
45− i.table = t
46− selectedRow := i.table.SelectedRow()
47− if selectedRow != nil {
48− if prevSelectedRow == nil || selectedRow[0] == prevSelectedRow[0] {
49− var log logging.LogMessage
50− for _, row := range logging.List() {
51− if row.ID == selectedRow[0] {
52− log = row
53− break
54− }
55− }
56− if log.ID != "" {
57− cmds = append(cmds, util.CmdHandler(selectedLogMsg(log)))
36+ switch msg.(type) {
37+ case pubsub.Event[logging.LogMessage]:
38+ i.setRows()
39+ return i, nil
40+ }
41+ prevSelectedRow := i.table.SelectedRow()
42+ t, cmd := i.table.Update(msg)
43+ cmds = append(cmds, cmd)
44+ i.table = t
45+ selectedRow := i.table.SelectedRow()
46+ if selectedRow != nil {
47+ if prevSelectedRow == nil || selectedRow[0] == prevSelectedRow[0] {
48+ var log logging.LogMessage
49+ for _, row := range logging.List() {
50+ if row.ID == selectedRow[0] {
51+ log = row
52+ break
5853 }
5954 }
55+ if log.ID != "" {
56+ cmds = append(cmds, util.CmdHandler(selectedLogMsg(log)))
57+ }
6058 }
6159 }
6260 return i, tea.Batch(cmds...)
6361}
6462
6563func (i *tableCmp) View() string {
66− return i.table.View()
64+ return styles.ForceReplaceBackgroundWithLipgloss(i.table.View(), styles.Background)
6765}
6866
6967func (i *tableCmp) GetSize() (int, int) {
@@ -128,6 +126,7 @@ func NewLogsTable() TableComponent {
128126 table.WithColumns(columns),
129127 table.WithStyles(defaultStyles),
130128 )
129+ tableModel.Focus()
131130 return &tableCmp{
132131 table: tableModel,
133132 }
internal/tui/page/logs.go+61−16
@@ -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+}