From 4047977b359754ba11b71406b6c4369ff7567fe4 Mon Sep 17 00:00:00 2001 From: divolgin Date: Thu, 1 Jul 2021 23:07:41 +0000 Subject: [PATCH] Make cursors visible on CTRL+C --- cmd/preflight/cli/run.go | 9 +++++++++ cmd/troubleshoot/cli/run.go | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/cmd/preflight/cli/run.go b/cmd/preflight/cli/run.go index 065e435c..dc0a25ec 100644 --- a/cmd/preflight/cli/run.go +++ b/cmd/preflight/cli/run.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net/http" "os" + "os/signal" "strings" "time" @@ -28,6 +29,14 @@ func runPreflights(v *viper.Viper, arg string) error { fmt.Print(cursor.Hide()) defer fmt.Print(cursor.Show()) + go func() { + signalChan := make(chan os.Signal, 1) + signal.Notify(signalChan, os.Interrupt) + <-signalChan + fmt.Print(cursor.Show()) + os.Exit(0) + }() + var preflightContent []byte var err error if strings.HasPrefix(arg, "secret/") { diff --git a/cmd/troubleshoot/cli/run.go b/cmd/troubleshoot/cli/run.go index 379758a0..14ec51eb 100644 --- a/cmd/troubleshoot/cli/run.go +++ b/cmd/troubleshoot/cli/run.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net/http" + "os/signal" "net/url" "os" @@ -33,6 +34,14 @@ func runTroubleshoot(v *viper.Viper, arg string) error { fmt.Print(cursor.Hide()) defer fmt.Print(cursor.Show()) + go func() { + signalChan := make(chan os.Signal, 1) + signal.Notify(signalChan, os.Interrupt) + <-signalChan + fmt.Print(cursor.Show()) + os.Exit(0) + }() + k8sConfig, err := k8sutil.GetRESTConfig() if err != nil { return errors.Wrap(err, "failed to convert kube flags to rest config")