mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31: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)
|
command := utils.ApplyTemplate(templateString, s)
|
||||||
|
|
||||||
cmd := s.OSCommand.ExecutableFromString(command)
|
cmd := s.OSCommand.ExecutableFromString(command)
|
||||||
|
// so long as this is commented in, the child process does not receive the interrupt
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
Setpgid: true,
|
Setpgid: true,
|
||||||
Pgid: 0,
|
Pgid: 0,
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||||
Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
Handler: gui.quit,
|
Handler: gui.quit,
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// ViewName: "",
|
ViewName: "",
|
||||||
// Key: gocui.KeyCtrlC,
|
Key: gocui.KeyCtrlC,
|
||||||
// Modifier: gocui.ModNone,
|
Modifier: gocui.ModNone,
|
||||||
// Handler: gui.quit,
|
Handler: gui.quit,
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
ViewName: "",
|
ViewName: "",
|
||||||
Key: gocui.KeyEsc,
|
Key: gocui.KeyEsc,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
@ -37,38 +35,16 @@ func (gui *Gui) RunWithSubprocesses() error {
|
||||||
func (gui *Gui) runCommand() error {
|
func (gui *Gui) runCommand() error {
|
||||||
gui.SubProcess.Stdout = os.Stdout
|
gui.SubProcess.Stdout = os.Stdout
|
||||||
gui.SubProcess.Stderr = os.Stdout
|
gui.SubProcess.Stderr = os.Stdout
|
||||||
// gui.SubProcess.Stdin = os.Stdin
|
gui.SubProcess.Stdin = os.Stdin
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
|
|
||||||
go func() {
|
|
||||||
<-c
|
<-c
|
||||||
gui.SubProcess.Process.Kill()
|
signal.Stop(c)
|
||||||
}()
|
|
||||||
|
|
||||||
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()
|
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))
|
fmt.Fprintf(os.Stdout, "\n%s\n\n", utils.ColoredString("+ "+strings.Join(gui.SubProcess.Args, " "), color.FgBlue))
|
||||||
|
|
@ -79,6 +55,8 @@ func (gui *Gui) runCommand() error {
|
||||||
gui.Log.Error(err)
|
gui.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signal.Stop(c)
|
||||||
|
|
||||||
gui.SubProcess.Stdout = ioutil.Discard
|
gui.SubProcess.Stdout = ioutil.Discard
|
||||||
gui.SubProcess.Stderr = ioutil.Discard
|
gui.SubProcess.Stderr = ioutil.Discard
|
||||||
gui.SubProcess.Stdin = nil
|
gui.SubProcess.Stdin = nil
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue