Explorar el Código

added functionality to interrupt the terminal when it is waiting for an input

Signed-off-by: Avi Vaid <avaid1996@gmail.com>
Avi Vaid hace 9 años
padre
commit
c4b07f4683
Se han modificado 1 ficheros con 9 adiciones y 3 borrados
  1. 9 3
      pkg/term/term.go

+ 9 - 3
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)
+		}
 	}()
 }