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:
parent
24dc23ac3b
commit
19ef77337a
1 changed files with 8 additions and 0 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue