mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Maybe fixed the test this time
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/kr/pty"
|
"github.com/kr/pty"
|
||||||
)
|
)
|
||||||
@ -19,7 +20,6 @@ import (
|
|||||||
// NOTE: You don't have to include a enter in the return data this function will do that for you
|
// NOTE: You don't have to include a enter in the return data this function will do that for you
|
||||||
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) {
|
func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) (errorMessage string, codeError error) {
|
||||||
cmdOutput := []string{}
|
cmdOutput := []string{}
|
||||||
isAlreadyClosed := false
|
|
||||||
|
|
||||||
splitCmd := ToArgv(command)
|
splitCmd := ToArgv(command)
|
||||||
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
|
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
|
||||||
@ -33,11 +33,11 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
return errorMessage, err
|
return errorMessage, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var waitForBufio sync.WaitGroup
|
||||||
|
waitForBufio.Add(1)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if !isAlreadyClosed {
|
_ = tty.Close()
|
||||||
isAlreadyClosed = true
|
|
||||||
_ = tty.Close()
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -55,13 +55,11 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
_, _ = tty.Write([]byte(toWrite + "\n"))
|
_, _ = tty.Write([]byte(toWrite + "\n"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
waitForBufio.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := cmd.Wait(); err != nil {
|
if err := cmd.Wait(); err != nil {
|
||||||
if !isAlreadyClosed {
|
waitForBufio.Wait()
|
||||||
isAlreadyClosed = true
|
|
||||||
_ = tty.Close()
|
|
||||||
}
|
|
||||||
return strings.Join(cmdOutput, " "), err
|
return strings.Join(cmdOutput, " "), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user