From 19ef77337a74af6e614b52d10316fe5ac0c8666b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 4 Feb 2025 12:59:23 +0100 Subject: [PATCH] main: reset the terminal properly on SIGINT,SIGTERM This commit fixes the issue that on `CTRL-C` (SIGINT) the progress is not properly cleared. It also catches SIGTERM for good measure. No test right now as this is hard to test automatically :/ Closes: https://github.com/osbuild/image-builder-cli/issues/123 --- cmd/image-builder/main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 1f5fa76..03c83ae 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -5,6 +5,8 @@ import ( "fmt" "io" "os" + "os/signal" + "syscall" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -179,6 +181,12 @@ func cmdBuild(cmd *cobra.Command, args []string) error { } pbar.Start() defer pbar.Stop() + go func() { + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + <-c + pbar.Stop() + }() var mf bytes.Buffer // XXX: check env here, i.e. if user is root and osbuild is installed