summaryrefslogtreecommitdiff
path: root/internal/tui/common
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-25 09:36:57 +0200
committerPaul Buetow <paul@buetow.org>2026-02-25 09:36:57 +0200
commit72ff234e97b16485553a79a876690a359058b110 (patch)
tree7b5133489ff48b0dee6857f4df2e82a704b8768c /internal/tui/common
parent1279ffb8f2efba54ff005cce91ba65c149cb1ee6 (diff)
Fix initial TUI sizing and align two-row sparklines
Diffstat (limited to 'internal/tui/common')
-rw-r--r--internal/tui/common/viewport.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/tui/common/viewport.go b/internal/tui/common/viewport.go
new file mode 100644
index 0000000..e1729db
--- /dev/null
+++ b/internal/tui/common/viewport.go
@@ -0,0 +1,38 @@
+package common
+
+import (
+ "os"
+
+ xterm "github.com/charmbracelet/x/term"
+)
+
+const (
+ defaultViewportWidth = 80
+ defaultViewportHeight = 24
+)
+
+// EffectiveViewport returns a usable terminal viewport size. Missing or invalid
+// dimensions are resolved from the active terminal when possible.
+func EffectiveViewport(width, height int) (int, int) {
+ if width > 0 && height > 0 {
+ return width, height
+ }
+
+ termWidth, termHeight, err := xterm.GetSize(os.Stdout.Fd())
+ if err == nil {
+ if width <= 0 && termWidth > 0 {
+ width = termWidth
+ }
+ if height <= 0 && termHeight > 0 {
+ height = termHeight
+ }
+ }
+
+ if width <= 0 {
+ width = defaultViewportWidth
+ }
+ if height <= 0 {
+ height = defaultViewportHeight
+ }
+ return width, height
+}