From c4b07f468388af6483913762d6ce6ae2ac9edf97 Mon Sep 17 00:00:00 2001 From: Avi Vaid Date: Thu, 4 Aug 2016 09:35:29 -0700 Subject: [PATCH] added functionality to interrupt the terminal when it is waiting for an input Signed-off-by: Avi Vaid --- pkg/term/term.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/term/term.go b/pkg/term/term.go index 1609a900a9..a769fd349f 100644 --- a/pkg/term/term.go +++ b/pkg/term/term.go @@ -6,6 +6,7 @@ package term import ( "errors" + "fmt" "io" "os" "os/signal" @@ -109,9 +110,14 @@ func SetRawTerminalOutput(fd uintptr) (*State, error) { func handleInterrupt(fd uintptr, state *State) { sigchan := make(chan os.Signal, 1) signal.Notify(sigchan, os.Interrupt) - go func() { - _ = <-sigchan - RestoreTerminal(fd, state) + for range sigchan { + // quit cleanly and the new terminal item is on a new line + fmt.Println() + signal.Stop(sigchan) + close(sigchan) + RestoreTerminal(fd, state) + os.Exit(1) + } }() }