From 54315ffde2c89f2a0a2c39e8c74de43913598f16 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Fri, 6 Apr 2018 18:57:57 +0300 Subject: [PATCH] clear output on 'cmd-enter' with 'shell-pipe' --- app.go | 11 ++++++----- eval.go | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app.go b/app.go index e63a75a..c22038e 100644 --- a/app.go +++ b/app.go @@ -22,6 +22,7 @@ type app struct { quitChan chan bool cmd *exec.Cmd cmdIn io.WriteCloser + cmdOutBuf []byte cmdHist []cmdItem cmdHistInd int } @@ -175,7 +176,7 @@ func waitKey() error { // // Prefix Wait Async Stdin Stdout Stderr UI action // $ No No Yes Yes Yes Pause and then resume -// % No No No Yes Yes Display output in statline +// % No No Yes Yes Yes Use statline for input/output // ! Yes No Yes Yes Yes Pause and then resume // & No Yes No No No Do nothing func (app *app) runShell(s string, args []string, prefix string) { @@ -233,20 +234,20 @@ func (app *app) runShell(s string, args []string, prefix string) { case "%": go func() { app.cmd = cmd + app.cmdOutBuf = nil app.ui.msg = "" app.ui.cmdPrefix = ">" reader := bufio.NewReader(out) - var buf []byte for { b, err := reader.ReadByte() if err == io.EOF { break } - buf = append(buf, b) - app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(buf)}}, 1} + app.cmdOutBuf = append(app.cmdOutBuf, b) + app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(app.cmdOutBuf)}}, 1} if b == '\n' || b == '\r' { - buf = nil + app.cmdOutBuf = nil } } diff --git a/eval.go b/eval.go index c19be9d..a37252f 100644 --- a/eval.go +++ b/eval.go @@ -459,6 +459,7 @@ func (e *callExpr) eval(app *app, args []string) { return case ">": io.WriteString(app.cmdIn, s+"\n") + app.cmdOutBuf = nil return case "!": log.Printf("shell-wait: %s", s)