Refactor shell-pipe reader (#2167)
This commit is contained in:
1 parent
1f8fb52889
commit
2adac2e155
1 file changed
+7
-11
@@ -614,25 +614,21 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.ui.echo("")
|
||||
|
||||
go func() {
|
||||
eol := false
|
||||
reader := bufio.NewReader(out)
|
||||
for {
|
||||
b, err := reader.ReadByte()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if eol {
|
||||
eol = false
|
||||
|
||||
app.cmdOutBuf = append(app.cmdOutBuf, b)
|
||||
if reader.Buffered() == 0 {
|
||||
app.ui.exprChan <- &callExpr{"echo", []string{string(app.cmdOutBuf)}, 1}
|
||||
}
|
||||
|
||||
if b == '\n' || b == '\r' {
|
||||
app.cmdOutBuf = nil
|
||||
}
|
||||
app.cmdOutBuf = append(app.cmdOutBuf, b)
|
||||
if b == '\n' || b == '\r' {
|
||||
eol = true
|
||||
}
|
||||
if reader.Buffered() > 0 {
|
||||
continue
|
||||
}
|
||||
app.ui.exprChan <- &callExpr{"echo", []string{string(app.cmdOutBuf)}, 1}
|
||||
}
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
|
||||
Reference in new issue
Block a user