diff options
author | Michael Kelley <michael.a.kelley@gmail.com> | 2021-04-03 21:19:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-04 13:19:43 +0900 |
commit | c8cd94a77294c1cac22e7559126d4671da898291 (patch) | |
tree | 7336deebe25fcbe6af08be216aa1fc88d45a71ed | |
parent | 764316a53d0eb60b315f0bbcd513de58ed57a876 (diff) |
Ensure proper ESC seq handling under Windows preview mode (#2430)
- Increase go routine buffer size
- Add time wait for nonblock getchr()
- Resolve #2429
-rw-r--r-- | src/tui/light_windows.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/tui/light_windows.go b/src/tui/light_windows.go index aa15a8a9..06e77ba0 100644 --- a/src/tui/light_windows.go +++ b/src/tui/light_windows.go @@ -5,11 +5,16 @@ package tui import ( "os" "syscall" + "time" "github.com/junegunn/fzf/src/util" "golang.org/x/sys/windows" ) +const ( + timeoutInterval = 10 +) + var ( consoleFlagsInput = uint32(windows.ENABLE_VIRTUAL_TERMINAL_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_EXTENDED_FLAGS) consoleFlagsOutput = uint32(windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | windows.ENABLE_PROCESSED_OUTPUT | windows.DISABLE_NEWLINE_AUTO_RETURN) @@ -60,7 +65,7 @@ func (r *LightRenderer) initPlatform() error { // channel for non-blocking reads. Buffer to make sure // we get the ESC sets: - r.ttyinChannel = make(chan byte, 12) + r.ttyinChannel = make(chan byte, 1024) // the following allows for non-blocking IO. // syscall.SetNonblock() is a NOOP under Windows. @@ -68,9 +73,6 @@ func (r *LightRenderer) initPlatform() error { fd := int(r.inHandle) b := make([]byte, 1) for { - // HACK: if run from PSReadline, something resets ConsoleMode to remove ENABLE_VIRTUAL_TERMINAL_INPUT. - _ = windows.SetConsoleMode(windows.Handle(r.inHandle), consoleFlagsInput) - _, err := util.Read(fd, b) if err == nil { r.ttyinChannel <- b[0] @@ -130,7 +132,7 @@ func (r *LightRenderer) getch(nonblock bool) (int, bool) { select { case bc := <-r.ttyinChannel: return int(bc), true - default: + case <-time.After(timeoutInterval * time.Millisecond): return 0, false } } else { |