execute: Open separate handles to /dev/tty (in, out, err)

# This will no longer cause 'Vim: Warning: Output is not to a terminal'
  fzf --bind 'enter:execute:vim {}' > /tmp/foo
This commit is contained in:
Junegunn Choi
2024-05-23 20:08:20 +09:00
parent d4216b0dcc
commit 3dee8778d0
9 changed files with 80 additions and 66 deletions

View File

@@ -138,17 +138,12 @@ func DurWithin(
return val
}
// IsTty returns true if stdin is a terminal
func IsTty() bool {
fd := os.Stdin.Fd()
// IsTty returns true if the file is a terminal
func IsTty(file *os.File) bool {
fd := file.Fd()
return isatty.IsTerminal(fd) || isatty.IsCygwinTerminal(fd)
}
// ToTty returns true if stdout is a terminal
func ToTty() bool {
return isatty.IsTerminal(os.Stdout.Fd())
}
// Once returns a function that returns the specified boolean value only once
func Once(nextResponse bool) func() bool {
state := nextResponse