clear output on 'cmd-enter' with 'shell-pipe'

This commit is contained in:
Gokcehan 2018-04-06 18:57:57 +03:00
parent bdf20aa451
commit 54315ffde2
2 changed files with 7 additions and 5 deletions

11
app.go
View File

@ -22,6 +22,7 @@ type app struct {
quitChan chan bool quitChan chan bool
cmd *exec.Cmd cmd *exec.Cmd
cmdIn io.WriteCloser cmdIn io.WriteCloser
cmdOutBuf []byte
cmdHist []cmdItem cmdHist []cmdItem
cmdHistInd int cmdHistInd int
} }
@ -175,7 +176,7 @@ func waitKey() error {
// //
// Prefix Wait Async Stdin Stdout Stderr UI action // Prefix Wait Async Stdin Stdout Stderr UI action
// $ No No Yes Yes Yes Pause and then resume // $ 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 // ! Yes No Yes Yes Yes Pause and then resume
// & No Yes No No No Do nothing // & No Yes No No No Do nothing
func (app *app) runShell(s string, args []string, prefix string) { 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 "%": case "%":
go func() { go func() {
app.cmd = cmd app.cmd = cmd
app.cmdOutBuf = nil
app.ui.msg = "" app.ui.msg = ""
app.ui.cmdPrefix = ">" app.ui.cmdPrefix = ">"
reader := bufio.NewReader(out) reader := bufio.NewReader(out)
var buf []byte
for { for {
b, err := reader.ReadByte() b, err := reader.ReadByte()
if err == io.EOF { if err == io.EOF {
break break
} }
buf = append(buf, b) app.cmdOutBuf = append(app.cmdOutBuf, b)
app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(buf)}}, 1} app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(app.cmdOutBuf)}}, 1}
if b == '\n' || b == '\r' { if b == '\n' || b == '\r' {
buf = nil app.cmdOutBuf = nil
} }
} }

View File

@ -459,6 +459,7 @@ func (e *callExpr) eval(app *app, args []string) {
return return
case ">": case ">":
io.WriteString(app.cmdIn, s+"\n") io.WriteString(app.cmdIn, s+"\n")
app.cmdOutBuf = nil
return return
case "!": case "!":
log.Printf("shell-wait: %s", s) log.Printf("shell-wait: %s", s)