1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

hopefully fixed the test now

This commit is contained in:
mjarkk 2018-11-03 09:36:38 +01:00
parent 8469239d84
commit cf1e9f79b1

View File

@ -20,7 +20,6 @@ import (
// 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) {
cmdOutput := []string{}
canAsk := true
splitCmd := ToArgv(command)
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
@ -34,6 +33,19 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
return errorMessage, err
}
var canAskLock sync.Mutex
canAskValue := true
canAsk := func() bool {
canAskLock.Lock()
defer canAskLock.Unlock()
return canAskValue
}
stopCanAsk := func() {
canAskLock.Lock()
defer canAskLock.Unlock()
canAskValue = false
}
var waitForBufio sync.WaitGroup
waitForBufio.Add(1)
@ -50,7 +62,7 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
// canAsk prefrents calls to output when the program is already closed
if canAsk {
if canAsk() {
toOutput := re.ReplaceAllString(scanner.Text(), "")
cmdOutput = append(cmdOutput, toOutput)
toWrite := output(toOutput)
@ -63,9 +75,7 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
}()
if err := cmd.Wait(); err != nil {
canAsk = false
//
stopCanAsk()
waitForBufio.Wait()
return strings.Join(cmdOutput, " "), err
}