mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Extract helper for starting a command with piped output
The fallback path in newPtyTask (taken when StartPty fails) needs the same start-the-command-with-a-pipe logic that newCmdTask uses, so pull it out into a helper that both can share. No behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
1dc7d4f589
commit
5209294a56
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/jesseduffield/lazygit/pkg/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/tasks"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error {
|
||||
|
|
@ -29,19 +30,9 @@ func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error
|
|||
start := func() (tasks.Cmd, io.Reader) {
|
||||
view.SetContentWidth(contentWidth)
|
||||
|
||||
var err error
|
||||
r, err = cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
gui.c.Log.Error(err)
|
||||
r = nil
|
||||
}
|
||||
cmd.Stderr = cmd.Stdout
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
gui.c.Log.Error(err)
|
||||
}
|
||||
|
||||
return tasks.ExecCmd{Cmd: cmd}, r
|
||||
execCmd, pipe := startCmdWithPipe(cmd, gui.c.Log)
|
||||
r = pipe
|
||||
return execCmd, pipe
|
||||
}
|
||||
|
||||
onClose := func() {
|
||||
|
|
@ -59,6 +50,24 @@ func (gui *Gui) newCmdTask(view *gocui.View, cmd *exec.Cmd, prefix string) error
|
|||
return nil
|
||||
}
|
||||
|
||||
// startCmdWithPipe starts cmd with its stdout and stderr going to a single
|
||||
// pipe, and returns the command along with the pipe's read end, in the shape
|
||||
// that NewCmdTask expects from its start func.
|
||||
func startCmdWithPipe(cmd *exec.Cmd, log *logrus.Entry) (tasks.Cmd, io.ReadCloser) {
|
||||
r, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
r = nil
|
||||
}
|
||||
cmd.Stderr = cmd.Stdout
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
return tasks.ExecCmd{Cmd: cmd}, r
|
||||
}
|
||||
|
||||
func (gui *Gui) newStringTask(view *gocui.View, str string) error {
|
||||
// using str so that if rendering the exact same thing we don't reset the origin
|
||||
return gui.newStringTaskWithKey(view, str, str)
|
||||
|
|
|
|||
Loading…
Reference in a new issue