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
1 changed files with 3 additions and 2 deletions

View File

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