m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-16 15:23:48 -05:00

Kill running preview process after 500ms when focus has changed

Close #1383
Close #1384
This commit is contained in:
Junegunn Choi
2018-09-27 15:27:08 +09:00
parent 27c40dc6b0
commit 0d748a0699
5 changed files with 82 additions and 18 deletions

View File

@@ -10,13 +10,15 @@ import (
)
// ExecCommand executes the given command with cmd
func ExecCommand(command string) *exec.Cmd {
func ExecCommand(command string, setpgid bool) *exec.Cmd {
return ExecCommandWith("cmd", command)
}
// ExecCommandWith executes the given command with cmd. _shell parameter is
// ignored on Windows.
func ExecCommandWith(_shell string, command string) *exec.Cmd {
// FIXME: setpgid is unused. We set it in the Unix implementation so that we
// can kill preview process with its child processes at once.
func ExecCommandWith(_shell string, command string, setpgid bool) *exec.Cmd {
cmd := exec.Command("cmd")
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: false,
@@ -26,12 +28,17 @@ func ExecCommandWith(_shell string, command string) *exec.Cmd {
return cmd
}
// KillCommand kills the process for the given command
func KillCommand(cmd *exec.Cmd) error {
return cmd.Process.Kill()
}
// IsWindows returns true on Windows
func IsWindows() bool {
return true
}
// SetNonBlock executes syscall.SetNonblock on file descriptor
// SetNonblock executes syscall.SetNonblock on file descriptor
func SetNonblock(file *os.File, nonblock bool) {
syscall.SetNonblock(syscall.Handle(file.Fd()), nonblock)
}