Skip to content

Commit

Permalink
fix: atomic.Uint32
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Aug 2, 2023
1 parent e3fac6f commit 9627f4b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tea
import (
"context"
"io"
"sync/atomic"

"github.com/muesli/termenv"
)
Expand Down Expand Up @@ -76,7 +77,7 @@ func WithoutCatchPanics() ProgramOption {
// This is mainly useful for testing.
func WithoutSignals() ProgramOption {
return func(p *Program) {
p.ignoreSignals.Store(true)
atomic.StoreUint32(&p.ignoreSignals, 1)
}
}

Expand Down
3 changes: 2 additions & 1 deletion options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tea

import (
"bytes"
"sync/atomic"
"testing"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func TestOptions(t *testing.T) {

t.Run("without signals", func(t *testing.T) {
p := NewProgram(nil, WithoutSignals())
if !p.ignoreSignals.Load() {
if atomic.LoadUint32(&p.ignoreSignals) == 0 {
t.Errorf("ignore signals should have been set")
}
})
Expand Down
8 changes: 4 additions & 4 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type Program struct {

// was the altscreen active before releasing the terminal?
altScreenWasActive bool
ignoreSignals atomic.Bool
ignoreSignals uint32

// Stores the original reference to stdin for cases where input is not a
// TTY on windows and we've automatically opened CONIN$ to receive input.
Expand Down Expand Up @@ -239,7 +239,7 @@ func (p *Program) handleSignals() chan struct{} {
return

case <-sig:
if !p.ignoreSignals.Load() {
if atomic.LoadUint32(&p.ignoreSignals) == 0 {
p.msgs <- QuitMsg{}
return
}
Expand Down Expand Up @@ -633,7 +633,7 @@ func (p *Program) shutdown(kill bool) {
// ReleaseTerminal restores the original terminal state and cancels the input
// reader. You can return control to the Program with RestoreTerminal.
func (p *Program) ReleaseTerminal() error {
p.ignoreSignals.Store(true)
atomic.StoreUint32(&p.ignoreSignals, 1)
p.cancelReader.Cancel()
p.waitForReadLoop()

Expand All @@ -649,7 +649,7 @@ func (p *Program) ReleaseTerminal() error {
// terminal to the former state when the program was running, and repaints.
// Use it to reinitialize a Program after running ReleaseTerminal.
func (p *Program) RestoreTerminal() error {
p.ignoreSignals.Store(false)
atomic.StoreUint32(&p.ignoreSignals, 0)

if err := p.initTerminal(); err != nil {
return err
Expand Down

0 comments on commit 9627f4b

Please sign in to comment.