Make terminal closure thread safe
This commit is contained in:
parent
be2918a616
commit
15b856abcc
1 changed files with 9 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
gocolor "image/color"
|
gocolor "image/color"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
"git.sr.ht/~sircmpwn/aerc2/lib/ui"
|
||||||
|
|
||||||
|
@ -92,11 +93,12 @@ type Terminal struct {
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
colors map[tcell.Color]tcell.Color
|
colors map[tcell.Color]tcell.Color
|
||||||
ctx *ui.Context
|
ctx *ui.Context
|
||||||
cursorShown bool
|
|
||||||
cursorPos vterm.Pos
|
cursorPos vterm.Pos
|
||||||
|
cursorShown bool
|
||||||
damage []vterm.Rect
|
damage []vterm.Rect
|
||||||
err error
|
err error
|
||||||
focus bool
|
focus bool
|
||||||
|
mutex sync.Mutex
|
||||||
onInvalidate func(d ui.Drawable)
|
onInvalidate func(d ui.Drawable)
|
||||||
pty *os.File
|
pty *os.File
|
||||||
start chan interface{}
|
start chan interface{}
|
||||||
|
@ -189,6 +191,8 @@ func (term *Terminal) flushTerminal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (term *Terminal) Close(err error) {
|
func (term *Terminal) Close(err error) {
|
||||||
|
term.mutex.Lock()
|
||||||
|
defer term.mutex.Unlock()
|
||||||
term.err = err
|
term.err = err
|
||||||
if term.vterm != nil {
|
if term.vterm != nil {
|
||||||
term.vterm.Close()
|
term.vterm.Close()
|
||||||
|
@ -229,6 +233,9 @@ func (term *Terminal) Draw(ctx *ui.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
term.mutex.Lock()
|
||||||
|
defer term.mutex.Unlock()
|
||||||
|
|
||||||
winsize := pty.Winsize{
|
winsize := pty.Winsize{
|
||||||
Cols: uint16(ctx.Width()),
|
Cols: uint16(ctx.Width()),
|
||||||
Rows: uint16(ctx.Height()),
|
Rows: uint16(ctx.Height()),
|
||||||
|
@ -239,6 +246,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
|
||||||
tty, err := pty.StartWithSize(term.cmd, &winsize)
|
tty, err := pty.StartWithSize(term.cmd, &winsize)
|
||||||
term.pty = tty
|
term.pty = tty
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
term.mutex.Unlock()
|
||||||
term.Close(err)
|
term.Close(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue