fix: lock mutex before checking altscreen state

This prevents the odd race condition where Enter- & ExitAltScreen
are called concurrently.
This commit is contained in:
Christian Muehlhaeuser 2022-10-13 04:33:34 +02:00
parent b8ef6f85ea
commit db664820d4
1 changed files with 6 additions and 6 deletions

View File

@ -268,13 +268,13 @@ func (r *standardRenderer) altScreen() bool {
} }
func (r *standardRenderer) enterAltScreen() { func (r *standardRenderer) enterAltScreen() {
r.mtx.Lock()
defer r.mtx.Unlock()
if r.altScreenActive { if r.altScreenActive {
return return
} }
r.mtx.Lock()
defer r.mtx.Unlock()
r.altScreenActive = true r.altScreenActive = true
r.out.AltScreen() r.out.AltScreen()
@ -291,13 +291,13 @@ func (r *standardRenderer) enterAltScreen() {
} }
func (r *standardRenderer) exitAltScreen() { func (r *standardRenderer) exitAltScreen() {
r.mtx.Lock()
defer r.mtx.Unlock()
if !r.altScreenActive { if !r.altScreenActive {
return return
} }
r.mtx.Lock()
defer r.mtx.Unlock()
r.altScreenActive = false r.altScreenActive = false
r.out.ExitAltScreen() r.out.ExitAltScreen()