mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 11:29:01 +00:00
Fix error when preview command failed to start
This commit is contained in:
parent
552414978e
commit
eaa413c566
@ -1855,13 +1855,9 @@ func (t *Terminal) Loop() {
|
|||||||
reader := bufio.NewReader(out)
|
reader := bufio.NewReader(out)
|
||||||
eofChan := make(chan bool)
|
eofChan := make(chan bool)
|
||||||
finishChan := make(chan bool, 1)
|
finishChan := make(chan bool, 1)
|
||||||
reapChan := make(chan bool)
|
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
reaps := 0
|
if err == nil {
|
||||||
if err != nil {
|
reapChan := make(chan bool)
|
||||||
t.reqBox.Set(reqPreviewDisplay, previewResult{version, []string{err.Error()}, 0, ""})
|
|
||||||
} else {
|
|
||||||
reaps = 2
|
|
||||||
lineChan := make(chan eachLine)
|
lineChan := make(chan eachLine)
|
||||||
// Goroutine 1 reads process output
|
// Goroutine 1 reads process output
|
||||||
go func() {
|
go func() {
|
||||||
@ -1874,6 +1870,7 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
eofChan <- true
|
eofChan <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Goroutine 2 periodically requests rendering
|
// Goroutine 2 periodically requests rendering
|
||||||
go func(version int64) {
|
go func(version int64) {
|
||||||
lines := []string{}
|
lines := []string{}
|
||||||
@ -1915,7 +1912,7 @@ func (t *Terminal) Loop() {
|
|||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
reapChan <- true
|
reapChan <- true
|
||||||
}(version)
|
}(version)
|
||||||
}
|
|
||||||
// Goroutine 3 is responsible for cancelling running preview command
|
// Goroutine 3 is responsible for cancelling running preview command
|
||||||
go func(version int64) {
|
go func(version int64) {
|
||||||
timer := time.NewTimer(previewDelayed)
|
timer := time.NewTimer(previewDelayed)
|
||||||
@ -1945,12 +1942,17 @@ func (t *Terminal) Loop() {
|
|||||||
timer.Stop()
|
timer.Stop()
|
||||||
reapChan <- true
|
reapChan <- true
|
||||||
}(version)
|
}(version)
|
||||||
<-eofChan
|
|
||||||
|
<-eofChan // Goroutine 1 finished
|
||||||
cmd.Wait() // NOTE: We should not call Wait before EOF
|
cmd.Wait() // NOTE: We should not call Wait before EOF
|
||||||
finishChan <- true
|
finishChan <- true // Tell Goroutine 3 to stop
|
||||||
for i := 0; i < reaps; i++ {
|
<-reapChan // Goroutine 2 and 3 finished
|
||||||
<-reapChan
|
<-reapChan
|
||||||
|
} else {
|
||||||
|
// Failed to start the command. Report the error immediately.
|
||||||
|
t.reqBox.Set(reqPreviewDisplay, previewResult{version, []string{err.Error()}, 0, ""})
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanTemporaryFiles()
|
cleanTemporaryFiles()
|
||||||
} else {
|
} else {
|
||||||
t.reqBox.Set(reqPreviewDisplay, previewResult{version, nil, 0, ""})
|
t.reqBox.Set(reqPreviewDisplay, previewResult{version, nil, 0, ""})
|
||||||
|
Loading…
Reference in New Issue
Block a user