From c9649ed1aad012c1ece3b7a5e0c5721d2a051c1b Mon Sep 17 00:00:00 2001 From: lalyos Date: Tue, 29 Nov 2016 08:46:15 +0100 Subject: [PATCH] double ctrl-c to exit --- termshare.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/termshare.go b/termshare.go index a7d13e7..9236864 100644 --- a/termshare.go +++ b/termshare.go @@ -244,12 +244,20 @@ func createSession() { if err := term.MakeRaw(os.Stdin); err != nil { panic(err) } + exitAllowed := false exitSignal := make(chan os.Signal) signal.Notify(exitSignal, os.Interrupt, syscall.SIGTERM) go func() { <-exitSignal - term.Restore(os.Stdin) - os.Exit(0) + if exitAllowed { + term.Restore(os.Stdin) + os.Exit(0) + } + exitAllowed = true + time.AfterFunc(500*time.Millisecond, func() { + exitAllowed = false + }) + }() defer term.Restore(os.Stdin) eof := make(chan bool, 1)