From 27f29d8328742b97c08c2186027d32cdc438345c Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 14 Jul 2025 22:08:09 +0000 Subject: [PATCH] term: remove duplicate flag and add comment on windows Both windows.ENABLE_PROCESSED_INPUT and windows.ENABLE_PROCESSED_OUTPUT have the same value of 0x1. Using makeRaw on a console output screen buffer handle wouldn't make sense since on Windows the input handle and the output screen buffer handle are two separate things. See https://learn.microsoft.com/en-us/windows/console/setconsolemode Change-Id: I19feadf8da303a1ada8e517399416a4730845900 GitHub-Last-Rev: 832fc7e8af65b1377f2e46653aed8011d51fd3b9 GitHub-Pull-Request: golang/term#14 Reviewed-on: https://go-review.googlesource.com/c/term/+/562779 Reviewed-by: Michael Pratt Reviewed-by: Laurent Demailly Reviewed-by: Jorropo LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui --- term_windows.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/term_windows.go b/term_windows.go index df6bf94..0ddd81c 100644 --- a/term_windows.go +++ b/term_windows.go @@ -20,12 +20,14 @@ func isTerminal(fd int) bool { return err == nil } +// This is intended to be used on a console input handle. +// See https://learn.microsoft.com/en-us/windows/console/setconsolemode func makeRaw(fd int) (*State, error) { var st uint32 if err := windows.GetConsoleMode(windows.Handle(fd), &st); err != nil { return nil, err } - raw := st &^ (windows.ENABLE_ECHO_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT | windows.ENABLE_PROCESSED_OUTPUT) + raw := st &^ (windows.ENABLE_ECHO_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT) raw |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT if err := windows.SetConsoleMode(windows.Handle(fd), raw); err != nil { return nil, err