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) { | |
| 202 | 202 | listPane := NewBorder(m.list) | |
| 203 | 203 | listPane.Label = "access logs" | |
| 204 | 204 | 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)) | |
| 206 | 206 | root.AddChild(0, ah, listSurf) | |
| 207 | 207 | ah += int(listSurf.Size.Height) | |
| 208 | 208 | } |
+1,
-1
| ... | ... | @@ -171,7 +171,7 @@ func (m *AddInvitePage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 171 | 171 | ah += int(errSurf.Size.Height) + 1 | |
| 172 | 172 | } | |
| 173 | 173 | ||
| 174 | - | listSurf, _ := m.list.Draw(createDrawCtx(ctx, ctx.Max.Height-uint16(ah))) | |
| 174 | + | listSurf, _ := m.list.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-ah)) | |
| 175 | 175 | root.AddChild(0, ah, listSurf) | |
| 176 | 176 | ||
| 177 | 177 | return root, nil |
+1,
-1
| ... | ... | @@ -158,7 +158,7 @@ func (m *LogsPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 158 | 158 | listPane := NewBorder(m.list) | |
| 159 | 159 | listPane.Label = "logs" | |
| 160 | 160 | m.focusBorder(listPane) | |
| 161 | - | listSurf, _ := listPane.Draw(createDrawCtx(ctx, ctx.Max.Height-4)) | |
| 161 | + | listSurf, _ := listPane.Draw(createDrawCtx(ctx, int(ctx.Max.Height)-4)) | |
| 162 | 162 | root.AddChild(0, 0, listSurf) | |
| 163 | 163 | } | |
| 164 | 164 |
+1,
-1
| ... | ... | @@ -126,7 +126,7 @@ func (m *PagesPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 126 | 126 | listPane := NewBorder(m.list) | |
| 127 | 127 | listPane.Label = "pages" | |
| 128 | 128 | 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)) | |
| 130 | 130 | root.AddChild(0, ah, listSurf) | |
| 131 | 131 | } | |
| 132 | 132 |
+1,
-1
| ... | ... | @@ -150,7 +150,7 @@ func (m *PubkeysPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 150 | 150 | ah += int(headerSurf.Size.Height) | |
| 151 | 151 | ||
| 152 | 152 | 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)) | |
| 154 | 154 | root.AddChild(0, ah, listSurf) | |
| 155 | 155 | ||
| 156 | 156 | segs := []vaxis.Segment{} |
+2,
-2
| ... | ... | @@ -130,7 +130,7 @@ func (m *TokensPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 130 | 130 | ah += int(headerSurf.Size.Height) | |
| 131 | 131 | ||
| 132 | 132 | 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)) | |
| 134 | 134 | root.AddChild(0, ah, listSurf) | |
| 135 | 135 | ||
| 136 | 136 | segs := []vaxis.Segment{} |
| ... | ... | @@ -149,7 +149,7 @@ func (m *TokensPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) { | |
| 149 | 149 | segs = append(segs, vaxis.Segment{Text: "\n"}) | |
| 150 | 150 | ||
| 151 | 151 | footer := richtext.New(segs) | |
| 152 | - | footerSurf, _ := footer.Draw(createDrawCtx(ctx, uint16(footerHeight))) | |
| 152 | + | footerSurf, _ := footer.Draw(createDrawCtx(ctx, footerHeight)) | |
| 153 | 153 | root.AddChild(0, int(h)-footerHeight, footerSurf) | |
| 154 | 154 | ||
| 155 | 155 | return root, nil |
+10,
-3
| ... | ... | @@ -50,16 +50,23 @@ var oj = vaxis.HexColor(0xFFCA80) | |
| 50 | 50 | var purp = vaxis.HexColor(0xBD93F9) | |
| 51 | 51 | var black = vaxis.HexColor(0x282A36) | |
| 52 | 52 | ||
| 53 | - | func createDrawCtx(ctx vxfw.DrawContext, h uint16) vxfw.DrawContext { | |
| 53 | + | func createDrawCtx(ctx vxfw.DrawContext, h int) vxfw.DrawContext { | |
| 54 | 54 | // setting some sane defaults to prevent exceptions | |
| 55 | 55 | 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) | |
| 58 | 63 | } | |
| 64 | + | ||
| 59 | 65 | var width uint16 = 80 | |
| 60 | 66 | if ctx.Max.Width < math.MaxUint16 { | |
| 61 | 67 | width = ctx.Max.Width | |
| 62 | 68 | } | |
| 69 | + | ||
| 63 | 70 | return vxfw.DrawContext{ | |
| 64 | 71 | Characters: ctx.Characters, | |
| 65 | 72 | Max: vxfw.Size{ |