Receive SIGINT only in RunInteractiveShell

Temporarily reset SIGINT signal handlers and receive SIGINT in
RunInteractiveShell. Do not try to kill the process in micro when signal
is received.
This commit is contained in:
niten94
2024-06-17 19:07:10 +08:00
parent 26ae1b95cc
commit f05d3582b3

View File

@@ -11,6 +11,7 @@ import (
shellquote "github.com/kballard/go-shellquote"
"github.com/zyedidia/micro/v2/internal/screen"
"github.com/zyedidia/micro/v2/internal/util"
)
// ExecCommand executes a command using exec
@@ -95,15 +96,11 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error
cmd.Stderr = os.Stderr
// This is a trap for Ctrl-C so that it doesn't kill micro
// Instead we trap Ctrl-C to kill the program we're running
// micro is killed if the signal is ignored only on Windows, so it is
// received
c := make(chan os.Signal, 1)
signal.Reset(os.Interrupt)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
cmd.Process.Kill()
}
}()
cmd.Start()
err = cmd.Wait()
@@ -117,6 +114,9 @@ func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error
// Start the screen back up
screen.TempStart(screenb)
signal.Notify(util.Sigterm, os.Interrupt)
signal.Stop(c)
return output, err
}