mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
hopefully fixed the test now
This commit is contained in:
parent
8469239d84
commit
cf1e9f79b1
@ -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
|
// 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{}
|
||||||
canAsk := true
|
|
||||||
|
|
||||||
splitCmd := ToArgv(command)
|
splitCmd := ToArgv(command)
|
||||||
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
|
cmd := exec.Command(splitCmd[0], splitCmd[1:]...)
|
||||||
@ -34,6 +33,19 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
return errorMessage, err
|
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
|
var waitForBufio sync.WaitGroup
|
||||||
waitForBufio.Add(1)
|
waitForBufio.Add(1)
|
||||||
|
|
||||||
@ -50,7 +62,7 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
scanner.Split(bufio.ScanWords)
|
scanner.Split(bufio.ScanWords)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
// canAsk prefrents calls to output when the program is already closed
|
// canAsk prefrents calls to output when the program is already closed
|
||||||
if canAsk {
|
if canAsk() {
|
||||||
toOutput := re.ReplaceAllString(scanner.Text(), "")
|
toOutput := re.ReplaceAllString(scanner.Text(), "")
|
||||||
cmdOutput = append(cmdOutput, toOutput)
|
cmdOutput = append(cmdOutput, toOutput)
|
||||||
toWrite := output(toOutput)
|
toWrite := output(toOutput)
|
||||||
@ -63,9 +75,7 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if err := cmd.Wait(); err != nil {
|
if err := cmd.Wait(); err != nil {
|
||||||
canAsk = false
|
stopCanAsk()
|
||||||
|
|
||||||
//
|
|
||||||
waitForBufio.Wait()
|
waitForBufio.Wait()
|
||||||
return strings.Join(cmdOutput, " "), err
|
return strings.Join(cmdOutput, " "), err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user