另客网go项目公用的代码库

terminal_check_windows.go 297B

123456789101112131415161718192021
  1. // +build !appengine,!js,windows
  2. package logrus
  3. import (
  4. "io"
  5. "os"
  6. "syscall"
  7. )
  8. func checkIfTerminal(w io.Writer) bool {
  9. switch v := w.(type) {
  10. case *os.File:
  11. var mode uint32
  12. err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode)
  13. return err == nil
  14. default:
  15. return false
  16. }
  17. }