ui: check bounds before drawing dialog

Check bounds before drawing a dialog window to avoid a panic when
resizing the terminal window.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-05-24 19:12:35 +02:00 committed by Robin Jarry
parent 62982a9a67
commit 71e5e2d795

View file

@ -181,8 +181,9 @@ func (aerc *Aerc) Focus(focus bool) {
func (aerc *Aerc) Draw(ctx *ui.Context) { func (aerc *Aerc) Draw(ctx *ui.Context) {
aerc.grid.Draw(ctx) aerc.grid.Draw(ctx)
if aerc.dialog != nil { if aerc.dialog != nil {
aerc.dialog.Draw(ctx.Subcontext(4, ctx.Height()/2-2, if w, h := ctx.Width(), ctx.Height(); w > 8 && h > 4 {
ctx.Width()-8, 4)) aerc.dialog.Draw(ctx.Subcontext(4, h/2-2, w-8, 4))
}
} }
} }