Skip to content
Myr

Refactor tui.TtyIn()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent c4cc789 · Browse files · 3 files+11 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+11 added−20 removed

  • other:+11 added−20 removed

3 files+11 added−20 removed

modified:src/tui/light_unix.go+8 added
5 unmodified lines
6 "errors"7 "os"8 "os/exec"9 "strings"10 "sync"11 "syscall"1213 "github.com/junegunn/fzf/src/util"14 "golang.org/x/sys/unix"
3 unmodified lines
18var (19 tty string20 ttyin *os.File21 ttyout *os.File22 mutex sync.Mutex23)2425func IsLightRendererSupported() bool {26 return true
45 unmodified lines
72 return in, nil73}7475func openTtyIn() (*os.File, error) {76 mutex.Lock()77 defer mutex.Unlock()7879 if ttyin != nil {80 return ttyin, nil81 }82 in, err := openTty(syscall.O_RDONLY)
3 unmodified lines
86 return in, err87}8889func openTtyOut() (*os.File, error) {90 mutex.Lock()91 defer mutex.Unlock()9293 if ttyout != nil {94 return ttyout, nil95 }96 out, err := openTty(syscall.O_WRONLY)
65 unmodified lines
modified:src/tui/ttyname_unix.go+3 added-10 removed
34 unmodified lines
35}3637// TtyIn returns terminal device to be used as STDIN, falls back to os.Stdin38func TtyIn() *os.File {39 in, err := os.OpenFile(consoleDevice, syscall.O_RDONLY, 0)40 if err != nil {41 tty := ttyname()42 if len(tty) > 0 {43 if in, err := os.OpenFile(tty, syscall.O_RDONLY, 0); err == nil {44 return in39 if in, err := openTtyIn(); err == nil {40 return in45 }46 }47 return os.Stdin41 }49 return in42 return os.Stdin43}
modified:src/terminal.go-10 removed
3469 unmodified lines
3470 t.tui.Close()3471 if t.history != nil {3472 t.history.append(string(t.input))3473 }34743475 /*3476 FIXME: It is not at all clear why this is required.3477 The following command will report 'not a tty', unless we open3478 /dev/tty *twice* after closing the standard input for 'reload'3479 in Reader.terminate().34803481 while : | fzf --bind 'start:reload:ls' --bind 'load:become:tty'; do echo; done3482 */3483 tui.TtyIn()3474 t.executor.Become(tui.TtyIn(), t.environ(), command)3475 }3476 case actExecute, actExecuteSilent:3477 t.executeCommand(a.a, false, a.t == actExecuteSilent, false, false)
926 unmodified lines