Render UI directly to /dev/tty

See https://github.com/junegunn/fzf/discussions/3792

This allows us to separately capture the standard error from fzf and its
child processes, and there's less chance of user errors of redirecting
the error stream and hiding fzf.
This commit is contained in:
Junegunn Choi
2024-05-14 16:29:22 +09:00
parent 6432f00f0d
commit d274d093af
3 changed files with 28 additions and 5 deletions

View File

@@ -14,6 +14,8 @@ import (
"golang.org/x/term"
)
var tty string
func IsLightRendererSupported() bool {
return true
}
@@ -48,12 +50,14 @@ func (r *LightRenderer) closePlatform() {
// NOOP
}
func openTtyIn() (*os.File, error) {
in, err := os.OpenFile(consoleDevice, syscall.O_RDONLY, 0)
func openTty(mode int) (*os.File, error) {
in, err := os.OpenFile(consoleDevice, mode, 0)
if err != nil {
tty := ttyname()
if len(tty) == 0 {
tty = ttyname()
}
if len(tty) > 0 {
if in, err := os.OpenFile(tty, syscall.O_RDONLY, 0); err == nil {
if in, err := os.OpenFile(tty, mode, 0); err == nil {
return in, nil
}
}
@@ -62,6 +66,14 @@ func openTtyIn() (*os.File, error) {
return in, nil
}
func openTtyIn() (*os.File, error) {
return openTty(syscall.O_RDONLY)
}
func openTtyOut() (*os.File, error) {
return openTty(syscall.O_WRONLY)
}
func (r *LightRenderer) setupTerminal() {
term.MakeRaw(r.fd())
}