terminal: check for context before calling it's methods

The terminal widget internally uses several context methods. Check that
context is not nil before calling any method to prevent panics.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-09-15 13:16:31 -05:00 committed by Robin Jarry
parent cf319129de
commit c7df28d632
1 changed files with 7 additions and 3 deletions

View File

@ -65,7 +65,9 @@ func (term *Terminal) Close(err error) {
if !term.closed && term.OnClose != nil { if !term.closed && term.OnClose != nil {
term.OnClose(err) term.OnClose(err)
} }
term.ctx.HideCursor() if term.ctx != nil {
term.ctx.HideCursor()
}
term.closed = true term.closed = true
} }
@ -126,7 +128,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
func (term *Terminal) draw() { func (term *Terminal) draw() {
term.vterm.Draw() term.vterm.Draw()
if term.focus && !term.closed { if term.focus && !term.closed && term.ctx != nil {
if !term.cursorShown { if !term.cursorShown {
term.ctx.HideCursor() term.ctx.HideCursor()
} else { } else {
@ -182,7 +184,9 @@ func (term *Terminal) HandleEvent(ev tcell.Event) bool {
term.draw() term.draw()
// Perform a tcell screen.Show() to show our updates // Perform a tcell screen.Show() to show our updates
// immediately // immediately
term.ctx.Show() if term.ctx != nil {
term.ctx.Show()
}
term.invalidate() term.invalidate()
return true return true
case *tcellterm.EventTitle: case *tcellterm.EventTitle: