isatty_windows.go 434 B

1234567891011121314151617181920
  1. // +build windows
  2. // +build !appengine
  3. package isatty
  4. import (
  5. "syscall"
  6. "unsafe"
  7. )
  8. var kernel32 = syscall.NewLazyDLL("kernel32.dll")
  9. var procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
  10. // IsTerminal return true if the file descriptor is terminal.
  11. func IsTerminal(fd uintptr) bool {
  12. var st uint32
  13. r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
  14. return r != 0 && e == 0
  15. }