Skip to content
Myr

Ensure proper ESC seq handling under Windows preview mode (#2430)

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

- Increase go routine buffer size - Add time wait for nonblock getchr() - Resolve #2429

authored by Michael Kelley · committed by GitHub · parent 764316a · Browse files · 1 file+7 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

1 file+7 added−5 removed

  • other:+7 added−5 removed

1 file+7 added−5 removed

modified:src/tui/light_windows.go+7 added-5 removed
3 unmodified lines
45import (6 "os"7 "syscall"8 "time"910 "github.com/junegunn/fzf/src/util"11 "golang.org/x/sys/windows"12)1314const (15 timeoutInterval = 1016)1718var (19 consoleFlagsInput = uint32(windows.ENABLE_VIRTUAL_TERMINAL_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_EXTENDED_FLAGS)20 consoleFlagsOutput = uint32(windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | windows.ENABLE_PROCESSED_OUTPUT | windows.DISABLE_NEWLINE_AUTO_RETURN)21)
42 unmodified lines
64 r.setupTerminal()6566 // channel for non-blocking reads. Buffer to make sure67 // we get the ESC sets:63 r.ttyinChannel = make(chan byte, 12)68 r.ttyinChannel = make(chan byte, 1024)6970 // the following allows for non-blocking IO.71 // syscall.SetNonblock() is a NOOP under Windows.72 go func() {73 fd := int(r.inHandle)74 b := make([]byte, 1)75 for {71 // HACK: if run from PSReadline, something resets ConsoleMode to remove ENABLE_VIRTUAL_TERMINAL_INPUT.72 _ = windows.SetConsoleMode(windows.Handle(r.inHandle), consoleFlagsInput)7376 _, err := util.Read(fd, b)77 if err == nil {78 r.ttyinChannel <- b[0]79 }
51 unmodified lines
131 if nonblock {132 select {133 case bc := <-r.ttyinChannel:134 return int(bc), true133 default:135 case <-time.After(timeoutInterval * time.Millisecond):136 return 0, false137 }138 } else {139 bc := <-r.ttyinChannel
3 unmodified lines