sequences.go 715 B

123456789101112131415161718192021222324252627282930313233343536
  1. // +build windows
  2. package sequences
  3. import (
  4. "syscall"
  5. "unsafe"
  6. )
  7. var (
  8. kernel32Dll *syscall.LazyDLL = syscall.NewLazyDLL("Kernel32.dll")
  9. setConsoleMode *syscall.LazyProc = kernel32Dll.NewProc("SetConsoleMode")
  10. )
  11. func EnableVirtualTerminalProcessing(stream syscall.Handle, enable bool) error {
  12. const ENABLE_VIRTUAL_TERMINAL_PROCESSING uint32 = 0x4
  13. var mode uint32
  14. err := syscall.GetConsoleMode(syscall.Stdout, &mode)
  15. if err != nil {
  16. return err
  17. }
  18. if enable {
  19. mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING
  20. } else {
  21. mode &^= ENABLE_VIRTUAL_TERMINAL_PROCESSING
  22. }
  23. ret, _, err := setConsoleMode.Call(uintptr(unsafe.Pointer(stream)), uintptr(mode))
  24. if ret == 0 {
  25. return err
  26. }
  27. return nil
  28. }