From 847c46421c7c29dd008f1e6f35d5a800b164db70 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 5 Apr 2018 23:06:52 +0300 Subject: [PATCH] fix race while drawing ui in 'shell-pipe' --- app.go | 6 ++---- ui.go | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index 19f0ec6..531fb9d 100644 --- a/app.go +++ b/app.go @@ -244,8 +244,7 @@ func (app *app) runShell(s string, args []string, prefix string) { break } buf = append(buf, b) - app.ui.msg = string(buf) - app.ui.draw(app.nav) + app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(buf)}}, 1} if b == '\n' { buf = nil } @@ -254,10 +253,9 @@ func (app *app) runShell(s string, args []string, prefix string) { if err := cmd.Wait(); err != nil { log.Printf("running shell: %s", err) } - app.nav.renew(app.ui.wins[0].h) app.cmd = nil app.ui.cmdPrefix = "" - app.ui.draw(app.nav) + app.ui.exprChan <- multiExpr{&callExpr{"reload", nil}, 1} }() } } diff --git a/ui.go b/ui.go index 166f667..f777e70 100644 --- a/ui.go +++ b/ui.go @@ -415,6 +415,7 @@ type ui struct { msg string regPrev *reg dirPrev *dir + exprChan chan multiExpr keyChan chan string evChan chan termbox.Event menuBuf *bytes.Buffer @@ -837,6 +838,8 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) { func (ui *ui) readExpr() <-chan multiExpr { ch := make(chan multiExpr) + ui.exprChan = ch + go func() { ch <- multiExpr{&callExpr{"redraw", nil}, 1}