Skip to content

Commit

Permalink
Guard legacy Windows vt100 setup syscall on more recent builds of Win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
tashian committed Aug 15, 2024
1 parent 0671a3d commit d591655
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions utils/sysutils/sysutils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit d591655

Please sign in to comment.