Skip to content

Commit

Permalink
handle ctrl+\ in addition to ctrl+c
Browse files Browse the repository at this point in the history
Signed-off-by: John Clark <[email protected]>
  • Loading branch information
inindev committed Dec 2, 2023
1 parent d0c3e88 commit 59cd548
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/mattn/go-tty"
Expand Down Expand Up @@ -42,13 +43,18 @@ func Monitor(port string, baud int) error {
defer tty.Close()

sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
signal.Notify(sig, os.Interrupt, syscall.SIGQUIT)
defer signal.Stop(sig)

go func() {
for {
<-sig
p.Write([]byte{0x1b, 0x03}) // send ctrl+c to tty
sig := <-sig
switch sig {
case os.Interrupt:
p.Write([]byte{0x1b, 0x03}) // send ctrl+c to tty
case syscall.SIGQUIT:
p.Write([]byte{0x1b, 0x1c}) // send ctrl+\ to tty
}
}
}()

Expand Down

0 comments on commit 59cd548

Please sign in to comment.