2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-07-02 01:02:03 +00:00
Hilbish/signal_unix.go
sammyette f239363a60
feat: suspend jobs via ctrl z
this was a bit of a pain to add and it still doesnt work
properly on this commit, but this is how it would be done
2023-02-19 15:13:52 -04:00

35 lines
837 B
Go

// +build darwin linux
package main
import (
"fmt"
"syscall"
"os"
"os/signal"
rt "github.com/arnodel/golua/runtime"
)
func handleSignals() {
c := make(chan os.Signal)
signal.Ignore(syscall.SIGTTOU, syscall.SIGTTIN)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGWINCH, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGQUIT, syscall.SIGTSTP)
for s := range c {
switch s {
case os.Interrupt: hooks.Emit("signal.sigint")
case syscall.SIGTERM: exit(0)
case syscall.SIGWINCH: hooks.Emit("signal.resize")
case syscall.SIGUSR1: hooks.Emit("signal.sigusr1")
case syscall.SIGUSR2: hooks.Emit("signal.sigusr2")
case syscall.SIGTSTP:
suspendHandler := hshMod.Get(rt.StringValue("suspend"))
_, err := rt.Call1(l.MainThread(), suspendHandler)
if err != nil {
fmt.Println(err)
}
}
}
}