feat: allow to disable signals (#721)

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2023-05-04 16:33:25 -03:00 committed by GitHub
parent 9cc3861bab
commit 5326d76c40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -70,6 +70,14 @@ func WithoutCatchPanics() ProgramOption {
} }
} }
// WithoutSignals will ignore OS signals.
// This is mainly useful for testing.
func WithoutSignals() ProgramOption {
return func(p *Program) {
p.ignoreSignals = true
}
}
// WithAltScreen starts the program with the alternate screen buffer enabled // WithAltScreen starts the program with the alternate screen buffer enabled
// (i.e. the program starts in full window mode). Note that the altscreen will // (i.e. the program starts in full window mode). Note that the altscreen will
// be automatically exited when the program quits. // be automatically exited when the program quits.

View File

@ -35,6 +35,13 @@ func TestOptions(t *testing.T) {
} }
}) })
t.Run("without signals", func(t *testing.T) {
p := NewProgram(nil, WithoutSignals())
if !p.ignoreSignals {
t.Errorf("ignore signals should have been set")
}
})
t.Run("filter", func(t *testing.T) { t.Run("filter", func(t *testing.T) {
p := NewProgram(nil, WithFilter(func(_ Model, msg Msg) Msg { return msg })) p := NewProgram(nil, WithFilter(func(_ Model, msg Msg) Msg { return msg }))
if p.filter == nil { if p.filter == nil {