mirror of
https://github.com/Luzifer/nginx-sso.git
synced 2024-12-20 21:01:17 +00:00
37 lines
715 B
Go
37 lines
715 B
Go
|
// +build windows
|
||
|
|
||
|
package sequences
|
||
|
|
||
|
import (
|
||
|
"syscall"
|
||
|
"unsafe"
|
||
|
)
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
ret, _, err := setConsoleMode.Call(uintptr(unsafe.Pointer(stream)), uintptr(mode))
|
||
|
if ret == 0 {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|