1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-12-07 23:22:40 +02:00

separate commits from cherry pick state

This commit is contained in:
Jesse Duffield
2020-03-26 21:11:21 +11:00
parent d027cf969c
commit 91a404d033
5 changed files with 74 additions and 51 deletions

View File

@@ -1,6 +1,7 @@
package commands
import (
"bufio"
"fmt"
"io/ioutil"
"os"
@@ -425,3 +426,31 @@ func Kill(cmd *exec.Cmd) error {
}
return cmd.Process.Kill()
}
func RunLineOutputCmd(cmd *exec.Cmd, onLine func(line string) (bool, error)) error {
stdoutPipe, err := cmd.StdoutPipe()
if err != nil {
return err
}
scanner := bufio.NewScanner(stdoutPipe)
scanner.Split(bufio.ScanLines)
if err := cmd.Start(); err != nil {
return err
}
for scanner.Scan() {
line := scanner.Text()
stop, err := onLine(line)
if err != nil {
return err
}
if stop {
cmd.Process.Kill()
break
}
}
cmd.Wait()
return nil
}