Exhaust queued entries in previewChan prior to calling preview script (#562)

* Use ranged for loop over channel

And rename variable "path" to "prev"

* Exhaust queued entries in previewChan prior to calling preview script
This commit is contained in:
neeshy 2021-01-19 01:42:01 +00:00 committed by GitHub
parent cb6ae713b4
commit 3f66f08b84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

34
nav.go
View File

@ -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
}
}
}