diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2024-05-15 00:28:56 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-05-15 00:28:56 +0900 |
commit | 86d92c17c4ad9ff12d550680208c0eae98dd776b (patch) | |
tree | e54840fcf20e91a14e556a5dda5a5f8d56a1dd0c /src | |
parent | c4cc7891b48067d69510e3356c71cecbe6cd4c5b (diff) |
Refactor tui.TtyIn()
Diffstat (limited to 'src')
-rw-r--r-- | src/terminal.go | 10 | ||||
-rw-r--r-- | src/tui/light_unix.go | 8 | ||||
-rw-r--r-- | src/tui/ttyname_unix.go | 13 |
3 files changed, 11 insertions, 20 deletions
diff --git a/src/terminal.go b/src/terminal.go index bdbc6bba..5179b0c9 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -3471,16 +3471,6 @@ func (t *Terminal) Loop() error { if t.history != nil { t.history.append(string(t.input)) } - - /* - FIXME: It is not at all clear why this is required. - The following command will report 'not a tty', unless we open - /dev/tty *twice* after closing the standard input for 'reload' - in Reader.terminate(). - - while : | fzf --bind 'start:reload:ls' --bind 'load:become:tty'; do echo; done - */ - tui.TtyIn() t.executor.Become(tui.TtyIn(), t.environ(), command) } case actExecute, actExecuteSilent: diff --git a/src/tui/light_unix.go b/src/tui/light_unix.go index e59c72ea..8d5a279b 100644 --- a/src/tui/light_unix.go +++ b/src/tui/light_unix.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "strings" + "sync" "syscall" "github.com/junegunn/fzf/src/util" @@ -18,6 +19,7 @@ var ( tty string ttyin *os.File ttyout *os.File + mutex sync.Mutex ) func IsLightRendererSupported() bool { @@ -71,6 +73,9 @@ func openTty(mode int) (*os.File, error) { } func openTtyIn() (*os.File, error) { + mutex.Lock() + defer mutex.Unlock() + if ttyin != nil { return ttyin, nil } @@ -82,6 +87,9 @@ func openTtyIn() (*os.File, error) { } func openTtyOut() (*os.File, error) { + mutex.Lock() + defer mutex.Unlock() + if ttyout != nil { return ttyout, nil } diff --git a/src/tui/ttyname_unix.go b/src/tui/ttyname_unix.go index bc6fe968..384115fb 100644 --- a/src/tui/ttyname_unix.go +++ b/src/tui/ttyname_unix.go @@ -36,15 +36,8 @@ func ttyname() string { // TtyIn returns terminal device to be used as STDIN, falls back to os.Stdin func TtyIn() *os.File { - in, err := os.OpenFile(consoleDevice, syscall.O_RDONLY, 0) - if err != nil { - tty := ttyname() - if len(tty) > 0 { - if in, err := os.OpenFile(tty, syscall.O_RDONLY, 0); err == nil { - return in - } - } - return os.Stdin + if in, err := openTtyIn(); err == nil { + return in } - return in + return os.Stdin } |