diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-26 09:47:28 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-26 09:47:28 +0200 |
| commit | 81ffb947201690088ef25a1839a8993bbfc27f03 (patch) | |
| tree | 948400add2b7df214c1587f04fe4ec9bd51c439a /internal/tui/dashboard/model.go | |
| parent | ad4d7fca20d80f71ccabef3281e3f80081f4db62 (diff) | |
tui: fix responsive layout and stream viewport chrome
Diffstat (limited to 'internal/tui/dashboard/model.go')
| -rw-r--r-- | internal/tui/dashboard/model.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/internal/tui/dashboard/model.go b/internal/tui/dashboard/model.go index 9b425b1..2ed53a1 100644 --- a/internal/tui/dashboard/model.go +++ b/internal/tui/dashboard/model.go @@ -14,6 +14,7 @@ import ( const defaultRefreshMs = 1000 const streamRefreshMs = 200 +const streamChromeRows = 4 // SnapshotSource is the dashboard data source. type SnapshotSource interface { @@ -73,7 +74,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case tea.WindowSizeMsg: m.width = msg.Width m.height = msg.Height - m.streamModel.SetViewport(msg.Width, msg.Height) + streamWidth, streamHeight := streamViewport(msg.Width, msg.Height) + m.streamModel.SetViewport(streamWidth, streamHeight) return m, nil case refreshTickMsg: snap := m.snapshot() @@ -188,7 +190,7 @@ func (m *Model) handleScrollKey(msg tea.KeyMsg) bool { case TabProcesses: return scrollOffset(keyStr, &m.processesOffset, m.maxProcessesRows()) case TabStream: - streamWidth, streamHeight := common.EffectiveViewport(m.width, m.height) + streamWidth, streamHeight := streamViewport(m.width, m.height) m.streamModel.SetViewport(streamWidth, streamHeight) return m.streamModel.HandleTeaKey(msg) default: @@ -267,6 +269,10 @@ func (m *Model) SetStreamSource(source *eventstream.RingBuffer) { // View renders the tab bar, active tab scaffold, and help bar. func (m Model) View() string { width, height := common.EffectiveViewport(m.width, m.height) + activeHeight := height + if m.activeTab == TabStream { + _, activeHeight = streamViewport(width, height) + } var b strings.Builder b.WriteString(renderTabBar(m.activeTab, width)) @@ -276,7 +282,7 @@ func (m Model) View() string { m.latest, &m.streamModel, width, - height, + activeHeight, m.syscallsOffset, m.filesOffset, m.filesDirGrouped, @@ -286,7 +292,7 @@ func (m Model) View() string { b.WriteString("\n") b.WriteString(common.HighlightStyle.Render("Press ? for help")) b.WriteString("\n") - b.WriteString(renderHelpBar(m.keys)) + b.WriteString(renderHelpBar(m.keys, width)) return common.ScreenStyle.Render(b.String()) } @@ -328,3 +334,12 @@ func renderActiveTab(tab Tab, snap *statsengine.Snapshot, streamModel *eventstre func streamTickCmd() tea.Cmd { return tea.Tick(streamRefreshMs*time.Millisecond, func(time.Time) tea.Msg { return streamTickMsg{} }) } + +func streamViewport(width, height int) (int, int) { + width, height = common.EffectiveViewport(width, height) + height -= streamChromeRows + if height < 1 { + height = 1 + } + return width, height +} |
