Adds signal handling
This commit is contained in:
parent
46fc8a4a97
commit
3972b3914e
26
main.go
26
main.go
|
@ -4,10 +4,12 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"tildegit.org/sloum/tally/termios"
|
||||
)
|
||||
|
||||
|
@ -158,7 +160,31 @@ func IsFunc(val string) bool {
|
|||
}
|
||||
}
|
||||
|
||||
func handleSignals(c <-chan os.Signal) {
|
||||
for {
|
||||
switch <-c {
|
||||
case syscall.SIGTSTP:
|
||||
termios.Restore()
|
||||
fmt.Print("\033[?25h")
|
||||
_ = syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
|
||||
case syscall.SIGCONT:
|
||||
termios.SetCharMode()
|
||||
fmt.Print("\033[?25l\033[2J")
|
||||
wb.Draw()
|
||||
case syscall.SIGINT:
|
||||
termios.Restore()
|
||||
fmt.Print("\033[?25h")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// watch for signals, send them to be handled
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT)
|
||||
go handleSignals(c)
|
||||
|
||||
args := os.Args
|
||||
if len(args) > 1 {
|
||||
path := ExpandedAbsFilepath(args[1])
|
||||
|
|
Loading…
Reference in New Issue