Commit 00f4477

Eric Bower  ·  2026-10-20 20:49:50 -0400 EDT
parent 07406e9
fix(tui): stricter bounds checking for tui height when drawing
7 files changed,  +17, -10
+1, -1
......@@ -202,7 +202,7 @@ func (m *AccessLogsPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
202202 listPane := NewBorder(m.list)
203203 listPane.Label = "access logs"
204204 m.focusBorder(listPane)
205- listSurf, _ := listPane.Draw(createDrawCtx(ctx, ctx.Max.Height-uint16(ah)-3))
205+ listSurf, _ := listPane.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-ah-3))
206206 root.AddChild(0, ah, listSurf)
207207 ah += int(listSurf.Size.Height)
208208 }
+1, -1
......@@ -171,7 +171,7 @@ func (m *AddInvitePage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
171171 ah += int(errSurf.Size.Height) + 1
172172 }
173173
174- listSurf, _ := m.list.Draw(createDrawCtx(ctx, ctx.Max.Height-uint16(ah)))
174+ listSurf, _ := m.list.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-ah))
175175 root.AddChild(0, ah, listSurf)
176176
177177 return root, nil
+1, -1
......@@ -158,7 +158,7 @@ func (m *LogsPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
158158 listPane := NewBorder(m.list)
159159 listPane.Label = "logs"
160160 m.focusBorder(listPane)
161- listSurf, _ := listPane.Draw(createDrawCtx(ctx, ctx.Max.Height-4))
161+ listSurf, _ := listPane.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-4))
162162 root.AddChild(0, 0, listSurf)
163163 }
164164
+1, -1
......@@ -126,7 +126,7 @@ func (m *PagesPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
126126 listPane := NewBorder(m.list)
127127 listPane.Label = "pages"
128128 listPane.Style = vaxis.Style{Foreground: oj}
129- listSurf, _ := listPane.Draw(createDrawCtx(ctx, ctx.Max.Height-uint16(ah)))
129+ listSurf, _ := listPane.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-ah))
130130 root.AddChild(0, ah, listSurf)
131131 }
132132
+1, -1
......@@ -150,7 +150,7 @@ func (m *PubkeysPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
150150 ah += int(headerSurf.Size.Height)
151151
152152 footerHeight := 3
153- listSurf, _ := m.list.Draw(createDrawCtx(ctx, ctx.Max.Height-uint16(ah)-uint16(footerHeight)))
153+ listSurf, _ := m.list.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-ah-footerHeight))
154154 root.AddChild(0, ah, listSurf)
155155
156156 segs := []vaxis.Segment{}
+2, -2
......@@ -130,7 +130,7 @@ func (m *TokensPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
130130 ah += int(headerSurf.Size.Height)
131131
132132 footerHeight := 3
133- listSurf, _ := m.list.Draw(createDrawCtx(ctx, ctx.Max.Height-uint16(ah)-uint16(footerHeight)))
133+ listSurf, _ := m.list.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-ah-footerHeight))
134134 root.AddChild(0, ah, listSurf)
135135
136136 segs := []vaxis.Segment{}
......@@ -149,7 +149,7 @@ func (m *TokensPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
149149 segs = append(segs, vaxis.Segment{Text: "\n"})
150150
151151 footer := richtext.New(segs)
152- footerSurf, _ := footer.Draw(createDrawCtx(ctx, uint16(footerHeight)))
152+ footerSurf, _ := footer.Draw(createDrawCtx(ctx, footerHeight))
153153 root.AddChild(0, int(h)-footerHeight, footerSurf)
154154
155155 return root, nil
+10, -3
......@@ -50,16 +50,23 @@ var oj = vaxis.HexColor(0xFFCA80)
5050 var purp = vaxis.HexColor(0xBD93F9)
5151 var black = vaxis.HexColor(0x282A36)
5252
53-func createDrawCtx(ctx vxfw.DrawContext, h uint16) vxfw.DrawContext {
53+func createDrawCtx(ctx vxfw.DrawContext, h int) vxfw.DrawContext {
5454 // setting some sane defaults to prevent exceptions
5555 var height uint16 = 1
56- if h >= height {
57- height = h
56+ switch {
57+ case h == -1:
58+ if ctx.Max.Height < math.MaxUint16 {
59+ height = ctx.Max.Height
60+ }
61+ case h >= 1:
62+ height = uint16(h)
5863 }
64+
5965 var width uint16 = 80
6066 if ctx.Max.Width < math.MaxUint16 {
6167 width = ctx.Max.Width
6268 }
69+
6370 return vxfw.DrawContext{
6471 Characters: ctx.Characters,
6572 Max: vxfw.Size{