GeezerVison is showing github.com — update logs · kozer/opencode@05d0e86
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .gitignore +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,5 @@ Thumbs.db | 41 | 41 | .env | 42 | 42 | .env.local | 43 | 43 |
| 44 | | -.opencode | | 44 | +.opencode/ | 45 | 45 |
| 46 | | -internal/assets/diff/index.mjs | 47 | | -cmd/test/* |
Collapse file Copy file name to clipboardExpand all lines: internal/tui/components/logs/details.go +2-27Lines changed: 2 additions & 27 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,6 @@ type DetailComponent interface { | 22 | 22 |
| 23 | 23 | type detailCmp struct { | 24 | 24 | width, height int | 25 | | - focused bool | 26 | 25 | currentLog logging.LogMessage | 27 | 26 | viewport viewport.Model | 28 | 27 | } | @@ -37,11 +36,6 @@ func (i *detailCmp) Init() tea.Cmd { | 37 | 36 | } | 38 | 37 |
| 39 | 38 | func (i *detailCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | 40 | | - var ( | 41 | | - cmd tea.Cmd | 42 | | - cmds []tea.Cmd | 43 | | - ) | 44 | | - | 45 | 39 | switch msg := msg.(type) { | 46 | 40 | case selectedLogMsg: | 47 | 41 | if msg.ID != i.currentLog.ID { | @@ -50,12 +44,7 @@ func (i *detailCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | 50 | 44 | } | 51 | 45 | } | 52 | 46 |
| 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 | 59 | 48 | } | 60 | 49 |
| 61 | 50 | func (i *detailCmp) updateContent() { | @@ -123,21 +112,7 @@ func getLevelStyle(level string) lipgloss.Style { | 123 | 112 | } | 124 | 113 |
| 125 | 114 | func (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) | 141 | 116 | } | 142 | 117 |
| 143 | 118 | func (i *detailCmp) GetSize() (int, int) { | |
Collapse file Copy file name to clipboardExpand all lines: internal/tui/components/logs/table.go +22-23Lines changed: 22 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,37 +33,35 @@ func (i *tableCmp) Init() tea.Cmd { | 33 | 33 |
| 34 | 34 | func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | 35 | 35 | 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 | 58 | 53 | } | 59 | 54 | } | | 55 | + if log.ID != "" { | | 56 | + cmds = append(cmds, util.CmdHandler(selectedLogMsg(log))) | | 57 | + } | 60 | 58 | } | 61 | 59 | } | 62 | 60 | return i, tea.Batch(cmds...) | 63 | 61 | } | 64 | 62 |
| 65 | 63 | func (i *tableCmp) View() string { | 66 | | - return i.table.View() | | 64 | + return styles.ForceReplaceBackgroundWithLipgloss(i.table.View(), styles.Background) | 67 | 65 | } | 68 | 66 |
| 69 | 67 | func (i *tableCmp) GetSize() (int, int) { | @@ -128,6 +126,7 @@ func NewLogsTable() TableComponent { | 128 | 126 | table.WithColumns(columns), | 129 | 127 | table.WithStyles(defaultStyles), | 130 | 128 | ) | | 129 | + tableModel.Focus() | 131 | 130 | return &tableCmp{ | 132 | 131 | table: tableModel, | 133 | 132 | } | |
Collapse file Copy file name to clipboard +61-16Lines changed: 61 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 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 | +} |
|