terminal_windows.go 602 B

123456789101112131415161718192021222324252627
  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
  6. package term
  7. import (
  8. "syscall"
  9. "unsafe"
  10. )
  11. var kernel32 = syscall.NewLazyDLL("kernel32.dll")
  12. var (
  13. procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
  14. )
  15. // IsTty returns true if the given file descriptor is a terminal.
  16. func IsTty(fd uintptr) bool {
  17. var st uint32
  18. r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
  19. return r != 0 && e == 0
  20. }