mirror of https://github.com/Hilbis/Hilbish
feat: commanders can exit via ctrl c (#313)
parent
826b0789cb
commit
41e5e3f789
|
@ -31,6 +31,8 @@ hilbish.run('wc -l', {
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix ansi attributes causing issues with text when cut off in greenhouse
|
- Fix ansi attributes causing issues with text when cut off in greenhouse
|
||||||
- `exec` command should return if no arg presented
|
- `exec` command should return if no arg presented
|
||||||
|
- Commanders can now be cancelled by Ctrl-C and wont hang the shell anymore.
|
||||||
|
See [issue 198](https://github.com/Rosettea/Hilbish/issues/198).
|
||||||
|
|
||||||
## [2.2.3] - 2024-04-27
|
## [2.2.3] - 2024-04-27
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
30
exec.go
30
exec.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -353,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