aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-21 21:23:30 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-21 21:23:30 -0400
commit15b856abccef75361ccd64221757c8b63ef1d441 (patch)
tree724b6bda254f8d27cfe7ab9bf5b98791010ce5e6 /widgets
parentbe2918a6164989aba5b18b4f642501ddb8801c10 (diff)
downloadaerc-15b856abccef75361ccd64221757c8b63ef1d441.tar.gz
Make terminal closure thread safe
Diffstat (limited to 'widgets')
-rw-r--r--widgets/terminal.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 7aaeda03..24925ae3 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -4,6 +4,7 @@ import (
gocolor "image/color"
"os"
"os/exec"
+ "sync"
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
@@ -92,11 +93,12 @@ type Terminal struct {
cmd *exec.Cmd
colors map[tcell.Color]tcell.Color
ctx *ui.Context
- cursorShown bool
cursorPos vterm.Pos
+ cursorShown bool
damage []vterm.Rect
err error
focus bool
+ mutex sync.Mutex
onInvalidate func(d ui.Drawable)
pty *os.File
start chan interface{}
@@ -189,6 +191,8 @@ func (term *Terminal) flushTerminal() {
}
func (term *Terminal) Close(err error) {
+ term.mutex.Lock()
+ defer term.mutex.Unlock()
term.err = err
if term.vterm != nil {
term.vterm.Close()
@@ -229,6 +233,9 @@ func (term *Terminal) Draw(ctx *ui.Context) {
return
}
+ term.mutex.Lock()
+ defer term.mutex.Unlock()
+
winsize := pty.Winsize{
Cols: uint16(ctx.Width()),
Rows: uint16(ctx.Height()),
@@ -239,6 +246,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
tty, err := pty.StartWithSize(term.cmd, &winsize)
term.pty = tty
if err != nil {
+ term.mutex.Unlock()
term.Close(err)
return
}