ui: avoid panic when terminal window is shrunk
When using a tiling window manager, aerc terminal dimensions may be greatly reduced after a new window has been created by :open. When the ui attempts to render to formerly-valid coordinates, SetCell & Printf may panic. Replace panic() with no-op in both functions to prevent aerc from crashing after a window shrink. Signed-off-by: Jason Stewart <support@eggplantsd.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
4c3565653a
commit
27978a859b
1 changed files with 4 additions and 2 deletions
|
@ -56,7 +56,8 @@ func (ctx *Context) Subcontext(x, y, width, height int) *Context {
|
||||||
func (ctx *Context) SetCell(x, y int, ch rune, style tcell.Style) {
|
func (ctx *Context) SetCell(x, y int, ch rune, style tcell.Style) {
|
||||||
width, height := ctx.viewport.Size()
|
width, height := ctx.viewport.Size()
|
||||||
if x >= width || y >= height {
|
if x >= width || y >= height {
|
||||||
panic(fmt.Errorf("Attempted to draw outside of context"))
|
// no-op when dims are inadequate
|
||||||
|
return
|
||||||
}
|
}
|
||||||
crunes := []rune{}
|
crunes := []rune{}
|
||||||
ctx.viewport.SetContent(x, y, ch, crunes, style)
|
ctx.viewport.SetContent(x, y, ch, crunes, style)
|
||||||
|
@ -68,7 +69,8 @@ func (ctx *Context) Printf(x, y int, style tcell.Style,
|
||||||
width, height := ctx.viewport.Size()
|
width, height := ctx.viewport.Size()
|
||||||
|
|
||||||
if x >= width || y >= height {
|
if x >= width || y >= height {
|
||||||
panic(fmt.Errorf("Attempted to draw outside of context"))
|
// no-op when dims are inadequate
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
str := fmt.Sprintf(format, a...)
|
str := fmt.Sprintf(format, a...)
|
||||||
|
|
Loading…
Reference in a new issue