1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 16:22:24 +03:00

Fixed test

This commit is contained in:
mjarkk
2018-11-03 09:12:45 +01:00
parent af54d7f015
commit 8469239d84
2 changed files with 15 additions and 18 deletions

View File

@@ -20,6 +20,7 @@ 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:]...)
@@ -48,17 +49,23 @@ func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(s
scanner := bufio.NewScanner(tty)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
toOutput := re.ReplaceAllString(scanner.Text(), "")
cmdOutput = append(cmdOutput, toOutput)
toWrite := output(toOutput)
if len(toWrite) > 0 {
_, _ = tty.Write([]byte(toWrite + "\n"))
// canAsk prefrents calls to output when the program is already closed
if canAsk {
toOutput := re.ReplaceAllString(scanner.Text(), "")
cmdOutput = append(cmdOutput, toOutput)
toWrite := output(toOutput)
if len(toWrite) > 0 {
_, _ = tty.Write([]byte(toWrite + "\n"))
}
}
}
waitForBufio.Done()
}()
if err := cmd.Wait(); err != nil {
canAsk = false
//
waitForBufio.Wait()
return strings.Join(cmdOutput, " "), err
}