Skip to content

Commit

Permalink
fix: lock mutex before checking altscreen state
Browse files Browse the repository at this point in the history
This prevents the odd race condition where Enter- & ExitAltScreen
are called concurrently.
  • Loading branch information
muesli committed Oct 13, 2022
1 parent b8ef6f8 commit db66482
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions standard_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ func (r *standardRenderer) altScreen() bool {
}

func (r *standardRenderer) enterAltScreen() {
r.mtx.Lock()
defer r.mtx.Unlock()

if r.altScreenActive {
return
}

r.mtx.Lock()
defer r.mtx.Unlock()

r.altScreenActive = true
r.out.AltScreen()

Expand All @@ -291,13 +291,13 @@ func (r *standardRenderer) enterAltScreen() {
}

func (r *standardRenderer) exitAltScreen() {
r.mtx.Lock()
defer r.mtx.Unlock()

if !r.altScreenActive {
return
}

r.mtx.Lock()
defer r.mtx.Unlock()

r.altScreenActive = false
r.out.ExitAltScreen()

Expand Down

0 comments on commit db66482

Please sign in to comment.