terminal_check_windows.go 572 B

12345678910111213141516171819202122232425262728293031323334
  1. // +build !appengine,!js,windows
  2. package logrus
  3. import (
  4. "io"
  5. "os"
  6. "syscall"
  7. sequences "github.com/konsorten/go-windows-terminal-sequences"
  8. )
  9. func initTerminal(w io.Writer) {
  10. switch v := w.(type) {
  11. case *os.File:
  12. sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true)
  13. }
  14. }
  15. func checkIfTerminal(w io.Writer) bool {
  16. var ret bool
  17. switch v := w.(type) {
  18. case *os.File:
  19. var mode uint32
  20. err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode)
  21. ret = (err == nil)
  22. default:
  23. ret = false
  24. }
  25. if ret {
  26. initTerminal(w)
  27. }
  28. return ret
  29. }