-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_windows.go
37 lines (29 loc) · 931 Bytes
/
main_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//go:build windows
// +build windows
package virtualterminal
import (
"syscall"
"golang.org/x/sys/windows"
)
const _PARAMETER_IS_INCORRECT = 87
func changeConsoleMode(console windows.Handle, bits uint32) (func(), error) {
var mode uint32
err := windows.GetConsoleMode(console, &mode)
if err != nil {
return func() {}, err
}
err = windows.SetConsoleMode(console, mode|bits)
if errno, ok := err.(syscall.Errno); ok && errno == _PARAMETER_IS_INCORRECT {
err = ErrNotSupported
}
return func() { windows.SetConsoleMode(console, mode) }, err
}
func enableStdin() (func(), error) {
return changeConsoleMode(windows.Stdin, windows.ENABLE_VIRTUAL_TERMINAL_INPUT)
}
func enableStdout() (func(), error) {
return changeConsoleMode(windows.Stdout, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
}
func enableStderr() (func(), error) {
return changeConsoleMode(windows.Stderr, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
}