Skip to content
Myr

Render UI directly to /dev/tty

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

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.

authored by Junegunn Choi · committed by Junegunn Choi · parent 6432f00 · Browse files · 3 files+28 added−5 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+28 added−5 removed

  • other:+28 added−5 removed

3 files+28 added−5 removed

modified:src/tui/light_unix.go+16 added-4 removed
12 unmodified lines
13 "golang.org/x/sys/unix"14 "golang.org/x/term"15)1617var tty string1819func IsLightRendererSupported() bool {20 return true21}22
26 unmodified lines
49func (r *LightRenderer) closePlatform() {50 // NOOP51}5251func openTtyIn() (*os.File, error) {52 in, err := os.OpenFile(consoleDevice, syscall.O_RDONLY, 0)53func openTty(mode int) (*os.File, error) {54 in, err := os.OpenFile(consoleDevice, mode, 0)55 if err != nil {56 if len(tty) == 0 {54 tty := ttyname()57 tty = ttyname()58 }59 if len(tty) > 0 {56 if in, err := os.OpenFile(tty, syscall.O_RDONLY, 0); err == nil {60 if in, err := os.OpenFile(tty, mode, 0); err == nil {61 return in, nil62 }63 }64 return nil, errors.New("failed to open " + consoleDevice)65 }66 return in, nil67}6869func openTtyIn() (*os.File, error) {70 return openTty(syscall.O_RDONLY)71}7273func openTtyOut() (*os.File, error) {74 return openTty(syscall.O_WRONLY)75}7677func (r *LightRenderer) setupTerminal() {78 term.MakeRaw(r.fd())79}80
55 unmodified lines
modified:src/tui/light_windows.go+5 added
94 unmodified lines
95 // not used96 return nil, nil97}9899func openTtyOut() (*os.File, error) {100 // not used101 return nil, nil102}103104func (r *LightRenderer) setupTerminal() error {105 if err := windows.SetConsoleMode(windows.Handle(r.outHandle), consoleFlagsOutput); err != nil {106 return err107 }
51 unmodified lines
modified:src/tui/light.go+7 added-1 removed
71 unmodified lines
72}7374func (r *LightRenderer) flush() {75 if r.queued.Len() > 0 {76 fmt.Fprint(os.Stderr, "\x1b[?7l\x1b[?25l"+r.queued.String()+"\x1b[?25h\x1b[?7h")76 fmt.Fprint(r.ttyout, "\x1b[?7l\x1b[?25l"+r.queued.String()+"\x1b[?25h\x1b[?7h")77 r.queued.Reset()78 }79}80
6 unmodified lines
87 clearOnExit bool88 prevDownTime time.Time89 clicks [][2]int90 ttyin *os.File91 ttyout *os.File92 buffer []byte93 origState *term.State94 width int95 height int
35 unmodified lines
131 in, err := openTtyIn()132 if err != nil {133 return nil, err134 }135 out, err := openTtyOut()136 if err != nil {137 out = os.Stderr138 }139 r := LightRenderer{140 closed: util.NewAtomicBool(false),141 theme: theme,142 forceBlack: forceBlack,143 mouse: mouse,144 clearOnExit: clearOnExit,145 ttyin: in,146 ttyout: out,147 yoffset: 0,148 tabstop: tabstop,149 fullscreen: fullscreen,150 upOneLine: false,
1011 unmodified lines