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: 832fc7e8af
GitHub-Pull-Request: golang/term#14
Reviewed-on: https://go-review.googlesource.com/c/term/+/562779
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Laurent Demailly <ldemailly@gmail.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Ayman Bagabas
2025-07-14 22:08:09 +00:00
committed by Michael Pratt
parent 30da5dd58f
commit 27f29d8328

View File

@@ -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