mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-07 23:52:04 -07:00
Fix deadlocks
This commit is contained in:
@@ -1837,18 +1837,6 @@ func (t *Terminal) cancelPreview() {
|
|||||||
t.killPreview(exitCancel)
|
t.killPreview(exitCancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) exit(getCode func() int) {
|
|
||||||
t.tui.Close()
|
|
||||||
code := getCode()
|
|
||||||
if code <= exitNoMatch && t.history != nil {
|
|
||||||
t.history.append(string(t.input))
|
|
||||||
}
|
|
||||||
// prof.Stop()
|
|
||||||
t.running = false
|
|
||||||
t.mutex.Unlock()
|
|
||||||
t.killPreview(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop is called to start Terminal I/O
|
// Loop is called to start Terminal I/O
|
||||||
func (t *Terminal) Loop() {
|
func (t *Terminal) Loop() {
|
||||||
// prof := profile.Start(profile.ProfilePath("/tmp/"))
|
// prof := profile.Start(profile.ProfilePath("/tmp/"))
|
||||||
@@ -2073,15 +2061,21 @@ func (t *Terminal) Loop() {
|
|||||||
var focusedIndex int32 = minItem.Index()
|
var focusedIndex int32 = minItem.Index()
|
||||||
var version int64 = -1
|
var version int64 = -1
|
||||||
running := true
|
running := true
|
||||||
|
code := exitError
|
||||||
|
exit := func(getCode func() int) {
|
||||||
|
t.tui.Close()
|
||||||
|
code = getCode()
|
||||||
|
if code <= exitNoMatch && t.history != nil {
|
||||||
|
t.history.append(string(t.input))
|
||||||
|
}
|
||||||
|
running = false
|
||||||
|
t.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
for running {
|
for running {
|
||||||
t.reqBox.Wait(func(events *util.Events) {
|
t.reqBox.Wait(func(events *util.Events) {
|
||||||
defer events.Clear()
|
defer events.Clear()
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
if !t.running {
|
|
||||||
running = false
|
|
||||||
t.mutex.Unlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for req, value := range *events {
|
for req, value := range *events {
|
||||||
switch req {
|
switch req {
|
||||||
case reqPrompt:
|
case reqPrompt:
|
||||||
@@ -2118,7 +2112,7 @@ func (t *Terminal) Loop() {
|
|||||||
case reqRedraw:
|
case reqRedraw:
|
||||||
t.redraw()
|
t.redraw()
|
||||||
case reqClose:
|
case reqClose:
|
||||||
t.exit(func() int {
|
exit(func() int {
|
||||||
if t.output() {
|
if t.output() {
|
||||||
return exitOk
|
return exitOk
|
||||||
}
|
}
|
||||||
@@ -2145,13 +2139,13 @@ func (t *Terminal) Loop() {
|
|||||||
t.previewer.version = value.(int64)
|
t.previewer.version = value.(int64)
|
||||||
t.printPreviewDelayed()
|
t.printPreviewDelayed()
|
||||||
case reqPrintQuery:
|
case reqPrintQuery:
|
||||||
t.exit(func() int {
|
exit(func() int {
|
||||||
t.printer(string(t.input))
|
t.printer(string(t.input))
|
||||||
return exitOk
|
return exitOk
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
case reqQuit:
|
case reqQuit:
|
||||||
t.exit(func() int { return exitInterrupt })
|
exit(func() int { return exitInterrupt })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2159,6 +2153,8 @@ func (t *Terminal) Loop() {
|
|||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// prof.Stop()
|
||||||
|
t.killPreview(code)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
looping := true
|
looping := true
|
||||||
|
Reference in New Issue
Block a user