summaryrefslogtreecommitdiff
path: root/internal/tui/common/viewport.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-05 21:50:58 +0200
committerPaul Buetow <paul@buetow.org>2026-03-05 21:50:58 +0200
commita4298701546b09fccb15ce30db7c7e3f4070525c (patch)
treeb3433014284ccd354be48efb2ce125ccaf236d7e /internal/tui/common/viewport.go
parent2bd89ced830f97fd12a672fddb6978d204a014fd (diff)
fix(tui): stabilize full-width layout and sparkline rendering
Diffstat (limited to 'internal/tui/common/viewport.go')
-rw-r--r--internal/tui/common/viewport.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/tui/common/viewport.go b/internal/tui/common/viewport.go
index 099a4e1..d54c886 100644
--- a/internal/tui/common/viewport.go
+++ b/internal/tui/common/viewport.go
@@ -1,13 +1,35 @@
package common
+import (
+ "os"
+
+ xterm "github.com/charmbracelet/x/term"
+)
+
const (
defaultViewportWidth = 80
defaultViewportHeight = 24
)
+var queryTerminalSize = func() (int, int, error) {
+ return xterm.GetSize(os.Stdout.Fd())
+}
+
// EffectiveViewport returns a usable terminal viewport size. Missing or invalid
// dimensions fall back to defaults.
func EffectiveViewport(width, height int) (int, int) {
+ if width <= 0 || height <= 0 {
+ terminalWidth, terminalHeight, err := queryTerminalSize()
+ if err == nil {
+ if width <= 0 && terminalWidth > 0 {
+ width = terminalWidth
+ }
+ if height <= 0 && terminalHeight > 0 {
+ height = terminalHeight
+ }
+ }
+ }
+
if width <= 0 {
width = defaultViewportWidth
}