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
This commit is contained in:
Michael Vogt 2025-02-04 12:59:23 +01:00 committed by Ondřej Budai
parent 24dc23ac3b
commit 19ef77337a

View file

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/signal"
"syscall"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -179,6 +181,12 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
} }
pbar.Start() pbar.Start()
defer pbar.Stop() 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 var mf bytes.Buffer
// XXX: check env here, i.e. if user is root and osbuild is installed // XXX: check env here, i.e. if user is root and osbuild is installed