terminal_check_windows.go 490 B

123456789101112131415161718192021222324252627
  1. // +build !appengine,!js,windows
  2. package logrus
  3. import (
  4. "io"
  5. "os"
  6. "golang.org/x/sys/windows"
  7. )
  8. func checkIfTerminal(w io.Writer) bool {
  9. switch v := w.(type) {
  10. case *os.File:
  11. handle := windows.Handle(v.Fd())
  12. var mode uint32
  13. if err := windows.GetConsoleMode(handle, &mode); err != nil {
  14. return false
  15. }
  16. mode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
  17. if err := windows.SetConsoleMode(handle, mode); err != nil {
  18. return false
  19. }
  20. return true
  21. }
  22. return false
  23. }