feat: add signal hooks for sigint and sigwinch (#80)

dev
TorchedSammy 2021-11-22 15:13:05 -05:00
parent 94a8b4ad47
commit af4c3885ae
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 9 additions and 3 deletions

7
lua.go
View File

@ -59,6 +59,13 @@ func LuaInit() {
hooks = bait.New() hooks = bait.New()
l.PreloadModule("bait", hooks.Loader) l.PreloadModule("bait", hooks.Loader)
// Add Ctrl-C handler
hooks.Em.On("signal.sigint", func() {
if !interactive {
os.Exit(0)
}
})
l.SetGlobal("complete", l.NewFunction(hshcomplete)) l.SetGlobal("complete", l.NewFunction(hshcomplete))
// Add more paths that Lua can require from // Add more paths that Lua can require from

View File

@ -265,13 +265,12 @@ func HandleSignals() {
for s := range c { for s := range c {
switch s { switch s {
case os.Interrupt: case os.Interrupt:
hooks.Em.Emit("signals.sigint")
if !running { if !running {
if !interactive {
os.Exit(0)
}
lr.ClearInput() lr.ClearInput()
} }
case syscall.SIGWINCH: case syscall.SIGWINCH:
hooks.Em.Emit("signals.resize")
if !running { if !running {
lr.Resize() lr.Resize()
} }