1
0
mirror of https://github.com/docker/cli.git synced 2026-01-13 18:22:35 +03:00

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

Signed-off-by: Avi Vaid <avaid1996@gmail.com>
Upstream-commit: c4b07f468388af6483913762d6ce6ae2ac9edf97
Component: engine
This commit is contained in:
Avi Vaid
2016-08-04 09:35:29 -07:00
parent 51a2e7806a
commit a8be04ca52

View File

@@ -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)
}
}()
}