From 2adac2e155b85288c76ff5fb1a83c0ef34063e5a Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Fri, 19 Sep 2025 20:22:49 +1000 Subject: [PATCH] Refactor `shell-pipe` reader (#2167) --- app.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app.go b/app.go index 23daa2bd..3eafa598 100644 --- a/app.go +++ b/app.go @@ -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 {