From 5326d76c402abcd4cc1ccbd9f354fda295363cd5 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 4 May 2023 16:33:25 -0300 Subject: [PATCH] feat: allow to disable signals (#721) Signed-off-by: Carlos Alexandro Becker Signed-off-by: Carlos A Becker --- options.go | 8 ++++++++ options_test.go | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/options.go b/options.go index a060722..7a63c67 100644 --- a/options.go +++ b/options.go @@ -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 // (i.e. the program starts in full window mode). Note that the altscreen will // be automatically exited when the program quits. diff --git a/options_test.go b/options_test.go index 71a3c6c..a66483d 100644 --- a/options_test.go +++ b/options_test.go @@ -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) { p := NewProgram(nil, WithFilter(func(_ Model, msg Msg) Msg { return msg })) if p.filter == nil {