Skip to content

Commit

Permalink
Leave doenter
Browse files Browse the repository at this point in the history
  • Loading branch information
fntlnz committed Jun 29, 2016
1 parent cbf1b61 commit dd6d00b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
7 changes: 0 additions & 7 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package main

import (
"bufio"
"fmt"
"io"
"log"
"os"
"os/signal"
"syscall"
"time"

"github.com/goburrow/serial"
"github.com/mitchellh/go-homedir"
Expand All @@ -26,6 +28,7 @@ func write(s serial.Port) {
}
}

// This functions handles signals to the main process and routes them to the VM
func sigh(s serial.Port) {
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan)
Expand All @@ -42,6 +45,28 @@ func sigh(s serial.Port) {
}
}

// This function allows the user to leave the tty by pressing Ctrl-c two times in a two seconds time frame
func detach() {
fmt.Fprintf(os.Stdout, "Send two times Ctrl-c (SIGINT) in order to leave doenter")
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan)

frec := false
for _ = range sigchan {
if frec {
os.Exit(0)
}

timer := time.NewTimer(time.Second * 2)
frec = true

go func() {
<-timer.C
frec = false
}()
}
}

func main() {
addr, err := homedir.Expand("~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty")
if err != nil {
Expand All @@ -60,5 +85,6 @@ func main() {

go read(s)
go write(s)
sigh(s)
go sigh(s)
detach()
}

0 comments on commit dd6d00b

Please sign in to comment.