mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
subprocesses that can be safely interrupted
This commit is contained in:
parent
f0f96de2b5
commit
365096d5b0
3 changed files with 13 additions and 34 deletions
|
|
@ -67,6 +67,7 @@ func (s *Service) ViewLogs() (*exec.Cmd, error) {
|
|||
command := utils.ApplyTemplate(templateString, s)
|
||||
|
||||
cmd := s.OSCommand.ExecutableFromString(command)
|
||||
// so long as this is commented in, the child process does not receive the interrupt
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
Pgid: 0,
|
||||
|
|
|
|||
|
|
@ -65,12 +65,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||
Modifier: gocui.ModNone,
|
||||
Handler: gui.quit,
|
||||
},
|
||||
// {
|
||||
// ViewName: "",
|
||||
// Key: gocui.KeyCtrlC,
|
||||
// Modifier: gocui.ModNone,
|
||||
// Handler: gui.quit,
|
||||
// },
|
||||
{
|
||||
ViewName: "",
|
||||
Key: gocui.KeyCtrlC,
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.quit,
|
||||
},
|
||||
{
|
||||
ViewName: "",
|
||||
Key: gocui.KeyEsc,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -37,40 +35,18 @@ func (gui *Gui) RunWithSubprocesses() error {
|
|||
func (gui *Gui) runCommand() error {
|
||||
gui.SubProcess.Stdout = os.Stdout
|
||||
gui.SubProcess.Stderr = os.Stdout
|
||||
// gui.SubProcess.Stdin = os.Stdin
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
gui.SubProcess.Stdin = os.Stdin
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
|
||||
go func() {
|
||||
signal.Notify(c, os.Interrupt)
|
||||
<-c
|
||||
signal.Stop(c)
|
||||
|
||||
gui.SubProcess.Process.Kill()
|
||||
}()
|
||||
|
||||
w, err := gui.SubProcess.StdinPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
input, err := reader.ReadByte()
|
||||
gui.Log.Warn("byte received")
|
||||
gui.Log.Warn(input)
|
||||
if input == 3 {
|
||||
gui.SubProcess.Process.Kill()
|
||||
break
|
||||
}
|
||||
if err != nil && err == io.EOF {
|
||||
gui.SubProcess.Process.Kill()
|
||||
break
|
||||
}
|
||||
w.Write([]byte{input})
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Fprintf(os.Stdout, "\n%s\n\n", utils.ColoredString("+ "+strings.Join(gui.SubProcess.Args, " "), color.FgBlue))
|
||||
|
||||
if err := gui.SubProcess.Run(); err != nil {
|
||||
|
|
@ -79,6 +55,8 @@ func (gui *Gui) runCommand() error {
|
|||
gui.Log.Error(err)
|
||||
}
|
||||
|
||||
signal.Stop(c)
|
||||
|
||||
gui.SubProcess.Stdout = ioutil.Discard
|
||||
gui.SubProcess.Stderr = ioutil.Discard
|
||||
gui.SubProcess.Stdin = nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue