diff --git a/internal/ui/etui/ephemeral_tui.go b/internal/ui/etui/ephemeral_tui.go index 8a7295583..8aa9dec81 100644 --- a/internal/ui/etui/ephemeral_tui.go +++ b/internal/ui/etui/ephemeral_tui.go @@ -23,7 +23,9 @@ import ( "context" "fmt" "os" + "os/signal" "sync" + "syscall" "github.com/anchore/syft/internal/logger" @@ -102,6 +104,8 @@ func OutputToEphemeralTUI(workerErrs <-chan error, subscription *partybus.Subscr ctx := context.Background() syftUIHandler := ui.NewHandler() + signals := interruptingSignals() + eventLoop: for { select { @@ -154,8 +158,23 @@ eventLoop: log.Errorf("cancelled (%+v)", err) } break eventLoop + case <-signals: + break eventLoop } } return nil } + +func interruptingSignals() chan os.Signal { + c := make(chan os.Signal, 1) // Note: A buffered channel is recommended for this; see https://golang.org/pkg/os/signal/#Notify + + interruptions := []os.Signal{ + syscall.SIGINT, + syscall.SIGTERM, + } + + signal.Notify(c, interruptions...) + + return c +}