From d59165538d2e06208705f07e7057ef7c54e4e608 Mon Sep 17 00:00:00 2001 From: Carl Tashian Date: Wed, 14 Aug 2024 18:23:37 -0700 Subject: [PATCH] Guard legacy Windows vt100 setup syscall on more recent builds of Windows --- utils/sysutils/sysutils_windows.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/utils/sysutils/sysutils_windows.go b/utils/sysutils/sysutils_windows.go index 4d8eacd83..19947c1e0 100644 --- a/utils/sysutils/sysutils_windows.go +++ b/utils/sysutils/sysutils_windows.go @@ -10,16 +10,21 @@ import ( func init() { var inMode, outMode uint32 - if err := windows.GetConsoleMode(windows.Stdin, &inMode); err == nil { - inMode |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT - if err := windows.SetConsoleMode(windows.Stdin, inMode); err != nil { - fmt.Fprintf(os.Stderr, "Failed to set console mode: %v", err) + maj, _, build := windows.RtlGetNtVersionNumbers() + if maj < 10 || (maj == 10 && build <= 14393) { + // the Windows 10 Anniversary Edition added VT100 support + // enable vterm support in older versions of the Windows terminal + if err := windows.GetConsoleMode(windows.Stdin, &inMode); err == nil { + inMode |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT + if err := windows.SetConsoleMode(windows.Stdin, inMode); err != nil { + fmt.Fprintf(os.Stderr, "Failed to set console mode: %v", err) + } } - } - if err := windows.GetConsoleMode(windows.Stdout, &outMode); err == nil { - outMode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING - if err := windows.SetConsoleMode(windows.Stdout, outMode); err != nil { - fmt.Fprintf(os.Stderr, "Failed to set console mode: %v", err) + if err := windows.GetConsoleMode(windows.Stdout, &outMode); err == nil { + outMode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING + if err := windows.SetConsoleMode(windows.Stdout, outMode); err != nil { + fmt.Fprintf(os.Stderr, "Failed to set console mode: %v", err) + } } } }