terminal_windows.go 645 B

12345678910111213141516171819202122232425262728
  1. // Based on ssh/terminal:
  2. // Copyright 2011 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. // +build windows,!appengine
  6. package logrus
  7. import (
  8. "syscall"
  9. "unsafe"
  10. )
  11. var kernel32 = syscall.NewLazyDLL("kernel32.dll")
  12. var (
  13. procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
  14. )
  15. // IsTerminal returns true if stderr's file descriptor is a terminal.
  16. func IsTerminal() bool {
  17. fd := syscall.Stderr
  18. var st uint32
  19. r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0)
  20. return r != 0 && e == 0
  21. }