| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package term |
| 6 |
|
| 7 |
import ( |
| 8 |
"errors" |
| 9 |
"os" |
| 10 |
"syscall" |
| 11 |
|
| 12 |
"golang.org/x/sys/windows" |
| 13 |
) |
| 14 |
|
| 15 |
func init() { |
| 16 |
enableVirtualTerminalProcessing = func(out *os.File) error { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
const ( |
| 26 |
ENABLE_PROCESSED_OUTPUT uint32 = 0x1 |
| 27 |
ENABLE_VIRTUAL_TERMINAL_PROCESSING uint32 = 0x4 |
| 28 |
) |
| 29 |
|
| 30 |
kernel32DLL := windows.NewLazySystemDLL("Kernel32.dll") |
| 31 |
setConsoleMode := kernel32DLL.NewProc("SetConsoleMode") |
| 32 |
|
| 33 |
var mode uint32 |
| 34 |
if err := syscall.GetConsoleMode(syscall.Handle(out.Fd()), &mode); err != nil { |
| 35 |
return err |
| 36 |
} |
| 37 |
|
| 38 |
mode |= ENABLE_PROCESSED_OUTPUT |
| 39 |
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
if ret, _, _ := setConsoleMode.Call(out.Fd(), uintptr(mode)); ret == 0 { |
| 44 |
return errors.New("SetConsoleMode failed") |
| 45 |
} |
| 46 |
return nil |
| 47 |
} |
| 48 |
} |