mirror of https://github.com/Hilbis/Hilbish
feat: make commanders exit with ctrl c
parent
62dc2e8b02
commit
ab4cb0fb54
|
@ -47,3 +47,10 @@ end)
|
||||||
bait.catch('hilbish.notification', function(notif)
|
bait.catch('hilbish.notification', function(notif)
|
||||||
doNotifyPrompt()
|
doNotifyPrompt()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local commander = require 'commander'
|
||||||
|
commander.register('loop', function()
|
||||||
|
while true do
|
||||||
|
-- nothing
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
29
exec.go
29
exec.go
|
@ -354,7 +354,34 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
|
||||||
sinks.Set(rt.StringValue("out"), rt.UserDataValue(stdout.ud))
|
sinks.Set(rt.StringValue("out"), rt.UserDataValue(stdout.ud))
|
||||||
sinks.Set(rt.StringValue("err"), rt.UserDataValue(stderr.ud))
|
sinks.Set(rt.StringValue("err"), rt.UserDataValue(stderr.ud))
|
||||||
|
|
||||||
luaexitcode, err := rt.Call1(l.MainThread(), rt.FunctionValue(cmd), rt.TableValue(luacmdArgs), rt.TableValue(sinks))
|
t := rt.NewThread(l)
|
||||||
|
sig := make(chan os.Signal)
|
||||||
|
exit := make(chan bool)
|
||||||
|
|
||||||
|
luaexitcode := rt.IntValue(63)
|
||||||
|
var err error
|
||||||
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
exit <- true
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
signal.Notify(sig, os.Interrupt)
|
||||||
|
select {
|
||||||
|
case <-sig:
|
||||||
|
t.KillContext()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
luaexitcode, err = rt.Call1(t, rt.FunctionValue(cmd), rt.TableValue(luacmdArgs), rt.TableValue(sinks))
|
||||||
|
exit <- true
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-exit
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "Error in command:\n" + err.Error())
|
fmt.Fprintln(os.Stderr, "Error in command:\n" + err.Error())
|
||||||
return interp.NewExitStatus(1)
|
return interp.NewExitStatus(1)
|
||||||
|
|
Loading…
Reference in New Issue