From f867b7695b98cb86bbc9568bc1b5a0d015fffbd4 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Sat, 17 Aug 2024 15:33:39 +0000 Subject: [PATCH] x/term: set missing VIRTUAL_TERMINAL_INPUT flag on Windows With this change the arrow keys work with Windows 11 Terminal After verifying https://github.com/containerd/console did work fine, unlike x/term, it's because they have: https://github.com/containerd/console/blob/v1.0.4/console_windows.go#L194 using the same flag fixed x/term for my program Small e2e test reproducing the issue and showing it being fixed can be ran using go run fortio.org/terminal/example@v0.6.0 # has the fix (or @latest) go run fortio.org/terminal/example@v0.5.1 -history .history # does not have working arrow keys/this fix Fixes golang/go#68830 Change-Id: If20addd054c76b889a52f933695467812be72306 GitHub-Last-Rev: 68e3ca0e19d5c5ac1848d8135638c809f593e035 GitHub-Pull-Request: golang/term#17 Reviewed-on: https://go-review.googlesource.com/c/term/+/603960 LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor Reviewed-by: Cherry Mui Reviewed-by: Ian Lance Taylor Commit-Queue: Ian Lance Taylor Reviewed-by: Alex Brainman --- term_windows.go | 1 + 1 file changed, 1 insertion(+) diff --git a/term_windows.go b/term_windows.go index 465f560..df6bf94 100644 --- a/term_windows.go +++ b/term_windows.go @@ -26,6 +26,7 @@ func makeRaw(fd int) (*State, error) { return nil, err } raw := st &^ (windows.ENABLE_ECHO_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT | windows.ENABLE_PROCESSED_OUTPUT) + raw |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT if err := windows.SetConsoleMode(windows.Handle(fd), raw); err != nil { return nil, err }