2018-11-18 00:28:29 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package sequences
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
kernel32Dll *syscall.LazyDLL = syscall.NewLazyDLL("Kernel32.dll")
|
|
|
|
setConsoleMode *syscall.LazyProc = kernel32Dll.NewProc("SetConsoleMode")
|
|
|
|
)
|
|
|
|
|
|
|
|
func EnableVirtualTerminalProcessing(stream syscall.Handle, enable bool) error {
|
|
|
|
const ENABLE_VIRTUAL_TERMINAL_PROCESSING uint32 = 0x4
|
|
|
|
|
|
|
|
var mode uint32
|
|
|
|
err := syscall.GetConsoleMode(syscall.Stdout, &mode)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if enable {
|
|
|
|
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
|
|
|
} else {
|
|
|
|
mode &^= ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
|
|
|
}
|
|
|
|
|
2020-05-23 22:06:21 +00:00
|
|
|
ret, _, err := setConsoleMode.Call(uintptr(stream), uintptr(mode))
|
2018-11-18 00:28:29 +00:00
|
|
|
if ret == 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|