From f78f9110e9932a559a225104dd8115514d30af59 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 10 Mar 2026 23:18:07 +0200 Subject: dashboard: unify viewport chrome calculation (task 388) --- internal/tui/dashboard/model.go | 13 ++++++------- internal/tui/dashboard/model_test.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'internal') diff --git a/internal/tui/dashboard/model.go b/internal/tui/dashboard/model.go index c852feb..0cc18f8 100644 --- a/internal/tui/dashboard/model.go +++ b/internal/tui/dashboard/model.go @@ -1356,20 +1356,19 @@ func bubbleTickCmdFn() tea.Cmd { } func streamViewport(width, height int) (int, int) { - width, height = common.EffectiveViewport(width, height) - height -= streamChromeRows - if height < 1 { - height = 1 - } - return width, height + return dashboardViewport(width, height, streamChromeRows) } func flameViewport(width, height int, showHelp bool) (int, int) { - width, height = common.EffectiveViewport(width, height) chromeRows := dashboardTabBarRows + dashboardHelpHintRows if showHelp { chromeRows = dashboardTabBarRows + dashboardExpandedHelpRows } + return dashboardViewport(width, height, chromeRows) +} + +func dashboardViewport(width, height, chromeRows int) (int, int) { + width, height = common.EffectiveViewport(width, height) height -= chromeRows if height < 1 { height = 1 diff --git a/internal/tui/dashboard/model_test.go b/internal/tui/dashboard/model_test.go index c2dfbba..59af73a 100644 --- a/internal/tui/dashboard/model_test.go +++ b/internal/tui/dashboard/model_test.go @@ -56,6 +56,25 @@ func firstLineContaining(value, needle string) string { return "" } +func TestStreamViewportUsesSharedChromeCalculator(t *testing.T) { + wantWidth, wantHeight := common.EffectiveViewport(120, 40) + wantHeight -= streamChromeRows + + width, height := streamViewport(120, 40) + if width != wantWidth || height != wantHeight { + t.Fatalf("streamViewport() = %dx%d, want %dx%d", width, height, wantWidth, wantHeight) + } +} + +func TestFlameViewportClampsHeightWithExpandedHelp(t *testing.T) { + wantWidth, _ := common.EffectiveViewport(80, 2) + + width, height := flameViewport(80, 2, true) + if width != wantWidth || height != 1 { + t.Fatalf("flameViewport() = %dx%d, want %dx%d", width, height, wantWidth, 1) + } +} + func TestKeySwitchingChangesActiveTab(t *testing.T) { m := NewModelWithConfig(nil, nil, 250, common.DefaultKeyMap()) -- cgit v1.2.3