repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
ee3ffda
parent
3f2624b
author
Eric Bower
date
2025-05-12 09:19:07 -0400 EDT
fix(tui): sane defaults when creating draw ctx

We are seeing some exceptions when using the draw ctx when terminal
pty's are too small.  This should hopefully prevent the exceptions from
happening.
1 files changed,  +12, -2
M pkg/tui/ui.go
+12, -2
 1@@ -4,6 +4,7 @@ import (
 2 	"errors"
 3 	"fmt"
 4 	"log/slog"
 5+	"math"
 6 	"strings"
 7 
 8 	"git.sr.ht/~rockorager/vaxis"
 9@@ -48,11 +49,20 @@ var purp = vaxis.HexColor(0xBD93F9)
10 var black = vaxis.HexColor(0x282A36)
11 
12 func createDrawCtx(ctx vxfw.DrawContext, h uint16) vxfw.DrawContext {
13+	// setting some sane defaults to prevent exceptions
14+	var height uint16 = 1
15+	if h >= height {
16+		height = h
17+	}
18+	var width uint16 = 80
19+	if ctx.Max.Width < math.MaxUint16 {
20+		width = ctx.Max.Width
21+	}
22 	return vxfw.DrawContext{
23 		Characters: ctx.Characters,
24 		Max: vxfw.Size{
25-			Width:  ctx.Max.Width,
26-			Height: h,
27+			Width:  width,
28+			Height: height,
29 		},
30 	}
31 }