diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-06-20 23:18:28 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-06-22 17:24:47 +0900 |
| commit | 7c2ffd3fef3f9131ee448a5f40d91835c8bd814d (patch) | |
| tree | 0cf1df14f976fde619d5084310fa972f07eec21d /src/util/util.go | |
| parent | db01e7dab65423cd1d14e15f5b15dfaabe760283 (diff) | |
| download | fzf-7c2ffd3fef3f9131ee448a5f40d91835c8bd814d.tar.gz | |
Make transform*, --info-command, and execute-silent cancellable
Users can press CTRL-C after 1 second to terminate the command.
Close #3883
Diffstat (limited to 'src/util/util.go')
| -rw-r--r-- | src/util/util.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/util/util.go b/src/util/util.go index ec5a1ea0..c8301363 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -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 } } |
