mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-14 19:55:49 -07:00
Make transform*, --info-command, and execute-silent cancellable
Users can press CTRL-C after 1 second to terminate the command. Close #3883
This commit is contained in:
@@ -144,12 +144,22 @@ func IsTty(file *os.File) bool {
|
||||
return isatty.IsTerminal(fd) || isatty.IsCygwinTerminal(fd)
|
||||
}
|
||||
|
||||
// RunOnce runs the given function only once
|
||||
func RunOnce(f func()) func() {
|
||||
once := Once(true)
|
||||
return func() {
|
||||
if once() {
|
||||
f()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Once returns a function that returns the specified boolean value only once
|
||||
func Once(nextResponse bool) func() bool {
|
||||
state := nextResponse
|
||||
return func() bool {
|
||||
prevState := state
|
||||
state = false
|
||||
state = !nextResponse
|
||||
return prevState
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user