diff --git a/action.go b/action.go index 45324b2..8366c89 100644 --- a/action.go +++ b/action.go @@ -229,7 +229,7 @@ func doSelectAll(i *Input, _ termbox.Event) { i.selection.Remove(l) } } - i.SendDraw() + i.SendDraw(false) } func doSelectVisible(i *Input, _ termbox.Event) { @@ -246,7 +246,7 @@ func doSelectVisible(i *Input, _ termbox.Event) { l.SetDirty(true) i.selection.Add(l) } - i.SendDraw() + i.SendDraw(false) } func doFinish(i *Input, _ termbox.Event) { @@ -345,7 +345,7 @@ func doInvertSelection(i *Input, _ termbox.Event) { return true }) - i.SendDraw() + i.SendDraw(false) } func doDeleteBackwardWord(i *Input, _ termbox.Event) { diff --git a/cli.go b/cli.go index 1d259d9..aaaf5ae 100644 --- a/cli.go +++ b/cli.go @@ -220,7 +220,7 @@ func (cli *CLI) Run() error { ctx.SetQuery([]rune(opts.OptQuery)) ctx.ExecQuery() } else { - ctx.SendDraw() + ctx.SendDraw(false) } ctx.WaitDone() diff --git a/ctx.go b/ctx.go index bb08e8f..57568cd 100644 --- a/ctx.go +++ b/ctx.go @@ -418,21 +418,21 @@ func (c Ctx) GetRawLineBufferSize() int { func (c *Ctx) ResetActiveLineBuffer() { c.rawLineBuffer.Replay() - c.SetActiveLineBuffer(c.rawLineBuffer) + c.SetActiveLineBuffer(c.rawLineBuffer, false) } -func (c *Ctx) SetActiveLineBuffer(l *RawLineBuffer) { +func (c *Ctx) SetActiveLineBuffer(l *RawLineBuffer, runningQuery bool) { c.activeLineBuffer = l go func(l *RawLineBuffer) { prev := time.Time{} for _ = range l.OutputCh() { if time.Since(prev) > time.Millisecond { - c.SendDraw() + c.SendDraw(runningQuery) prev = time.Now() } } - c.SendDraw() + c.SendDraw(runningQuery) }(l) } diff --git a/filter.go b/filter.go index dc563c4..6aeeb3e 100644 --- a/filter.go +++ b/filter.go @@ -159,7 +159,7 @@ func (f *Filter) Work(cancel chan struct{}, q HubReq) { buf.onEnd = func() { f.SendStatusMsg("") } buf.Accept(filter) - f.SetActiveLineBuffer(buf) + f.SetActiveLineBuffer(buf, true) } if ! f.config.StickySelection { diff --git a/hub.go b/hub.go index c446327..d4e1663 100644 --- a/hub.go +++ b/hub.go @@ -123,11 +123,11 @@ func (h *Hub) SendDrawPrompt() { } // SendDraw sends a request to redraw the terminal display -func (h *Hub) SendDraw() { +func (h *Hub) SendDraw(runningQuery bool) { trace("Hub.SendDraw: START") defer trace("Hub.SendDraw: END") // to make sure interface is nil, I need to EXPLICITLY set nil - req := HubReq{nil, nil} + req := HubReq{runningQuery, nil} send(h.DrawCh(), req, h.isSync) } diff --git a/input.go b/input.go index 3a8075e..0c85206 100644 --- a/input.go +++ b/input.go @@ -40,7 +40,7 @@ func (i *Input) handleInputEvent(ev termbox.Event) { case termbox.EventError: //update = false case termbox.EventResize: - i.SendDraw() + i.SendDraw(false) case termbox.EventKey: // ModAlt is a sequence of letters with a leading \x1b (=Esc). // It would be nice if termbox differentiated this for us, but diff --git a/layout.go b/layout.go index 0b03c2d..38bfd25 100644 --- a/layout.go +++ b/layout.go @@ -75,7 +75,7 @@ func IsValidVerticalAnchor(anchor VerticalAnchor) bool { type Layout interface { PrintStatus(string, time.Duration) DrawPrompt() - DrawScreen() + DrawScreen(bool) MovePage(PagingRequest) (moved bool) } @@ -373,30 +373,36 @@ func (l *ListArea) SetDirty(dirty bool) { } // Draw displays the ListArea on the screen -func (l *ListArea) Draw(parent Layout, perPage int) { +func (l *ListArea) Draw(parent Layout, perPage int, runningQuery bool) { trace("ListArea.Draw: START") defer trace("ListArea.Draw: END") currentPage := l.currentPage linebuf := l.GetCurrentLineBuffer() - bufsiz := linebuf.Size() - page := currentPage.page - for ; page > 1; { - if (currentPage.perPage * (page - 1) < bufsiz) && - (currentPage.perPage * page) >= bufsiz { - break - } - page--; - } - if currentPage.page != page { - currentPage.page = page - parent.DrawPrompt() + // Should only get into this clause if we are RUNNING A QUERY. + // regular paging shouldn't be affected. + if runningQuery { + bufsiz := linebuf.Size() + page := currentPage.page + + for ; page > 1; { + if (currentPage.perPage * (page - 1) < bufsiz) && + (currentPage.perPage * page) >= bufsiz { + break + } + + page--; + } + if currentPage.page != page { + currentPage.page = page + parent.DrawPrompt() + } } pf := PageCrop{perPage: currentPage.perPage, currentPage: currentPage.page} buf := pf.Crop(linebuf) - bufsiz = buf.Size() + bufsiz := buf.Size() // previously drawn lines are cached. first, truncate the cache // to current size of the drawable area @@ -584,7 +590,7 @@ func (l *BasicLayout) DrawPrompt() { } // DrawScreen draws the entire screen -func (l *BasicLayout) DrawScreen() { +func (l *BasicLayout) DrawScreen(runningQuery bool) { trace("DrawScreen: START") defer trace("DrawScreen: END") @@ -595,7 +601,7 @@ func (l *BasicLayout) DrawScreen() { } l.DrawPrompt() - l.list.Draw(l, perPage) + l.list.Draw(l, perPage, runningQuery) if err := screen.Flush(); err != nil { return diff --git a/reader.go b/reader.go index 26c51c4..12344c5 100644 --- a/reader.go +++ b/reader.go @@ -59,7 +59,7 @@ func (b *BufferReader) Loop() { refresh = time.AfterFunc(100*time.Millisecond, func() { if !b.ExecQuery() { - b.SendDraw() + b.SendDraw(false) } m.Lock() defer m.Unlock() diff --git a/view.go b/view.go index 45f3182..d8501da 100644 --- a/view.go +++ b/view.go @@ -53,12 +53,15 @@ func (v *View) Loop() { r.Done() case lines := <-v.DrawCh(): tmp := lines.DataInterface() - if name, ok := tmp.(string); ok { - if name == "prompt" { + switch tmp.(type) { + case string: + if tmp.(string) == "prompt" { v.drawPrompt() } - } else { - v.drawScreen() + case bool: + v.drawScreen(tmp.(bool)) + default: + v.drawScreen(false) } lines.Done() } @@ -69,10 +72,10 @@ func (v *View) printStatus(r StatusMsgRequest) { v.layout.PrintStatus(r.message, r.clearDelay) } -func (v *View) drawScreen() { +func (v *View) drawScreen(runningQuery bool) { v.mutex.Lock() defer v.mutex.Unlock() - v.layout.DrawScreen() + v.layout.DrawScreen(runningQuery) } func (v *View) drawPrompt() { @@ -86,6 +89,6 @@ func (v *View) movePage(p PagingRequest) { defer v.mutex.Unlock() if v.layout.MovePage(p) { - v.layout.DrawScreen() + v.layout.DrawScreen(false) } }