Refactor tui.TtyIn()

This commit is contained in:
Junegunn Choi
2024-05-15 00:28:56 +09:00
parent c4cc7891b4
commit 86d92c17c4
3 changed files with 11 additions and 20 deletions

View File

@@ -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
}