Skip to content

Commit

Permalink
Exhaust queued entries in previewChan prior to calling preview script (
Browse files Browse the repository at this point in the history
…#562)

* Use ranged for loop over channel

And rename variable "path" to "prev"

* Exhaust queued entries in previewChan prior to calling preview script
  • Loading branch information
neeshy authored Jan 19, 2021
1 parent cb6ae71 commit 3f66f08
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,23 +460,35 @@ func (nav *nav) position() {
}

func (nav *nav) previewLoop(ui *ui) {
var path string
for {
p, ok := <-nav.previewChan
if !ok {
return
var prev string
for path := range nav.previewChan {
var clear bool
if len(path) == 0 {
clear = true
}
if len(p) != 0 {
win := ui.wins[len(ui.wins)-1]
nav.preview(p, win)
path = p
} else if len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
cmd := exec.Command(gOpts.cleaner, path)
loop:
for {
select {
case path = <-nav.previewChan:
if len(path) == 0 {
clear = true
}
default:
break loop
}
}
if clear && len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
cmd := exec.Command(gOpts.cleaner, prev)
if err := cmd.Run(); err != nil {
log.Printf("cleaning preview: %s", err)
}
nav.volatilePreview = false
}
if len(path) != 0 {
win := ui.wins[len(ui.wins)-1]
nav.preview(path, win)
prev = path
}
}
}

Expand Down

0 comments on commit 3f66f08

Please sign in to comment.