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:
parent
cb6ae713b4
commit
3f66f08b84
34
nav.go
34
nav.go
@ -460,23 +460,35 @@ func (nav *nav) position() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) previewLoop(ui *ui) {
|
func (nav *nav) previewLoop(ui *ui) {
|
||||||
var path string
|
var prev string
|
||||||
for {
|
for path := range nav.previewChan {
|
||||||
p, ok := <-nav.previewChan
|
var clear bool
|
||||||
if !ok {
|
if len(path) == 0 {
|
||||||
return
|
clear = true
|
||||||
}
|
}
|
||||||
if len(p) != 0 {
|
loop:
|
||||||
win := ui.wins[len(ui.wins)-1]
|
for {
|
||||||
nav.preview(p, win)
|
select {
|
||||||
path = p
|
case path = <-nav.previewChan:
|
||||||
} else if len(gOpts.previewer) != 0 && len(gOpts.cleaner) != 0 && nav.volatilePreview {
|
if len(path) == 0 {
|
||||||
cmd := exec.Command(gOpts.cleaner, path)
|
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 {
|
if err := cmd.Run(); err != nil {
|
||||||
log.Printf("cleaning preview: %s", err)
|
log.Printf("cleaning preview: %s", err)
|
||||||
}
|
}
|
||||||
nav.volatilePreview = false
|
nav.volatilePreview = false
|
||||||
}
|
}
|
||||||
|
if len(path) != 0 {
|
||||||
|
win := ui.wins[len(ui.wins)-1]
|
||||||
|
nav.preview(path, win)
|
||||||
|
prev = path
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user