terminal_notwindows.go 486 B

1234567891011121314151617181920212223
  1. // +build linux darwin freebsd openbsd netbsd dragonfly
  2. // +build !appengine
  3. package terminal
  4. import (
  5. "io"
  6. "os"
  7. "syscall"
  8. "unsafe"
  9. )
  10. // IsTerminal returns true if stderr's file descriptor is a terminal.
  11. func IsTerminal(f io.Writer) bool {
  12. var termios Termios
  13. switch v := f.(type) {
  14. case *os.File:
  15. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(v.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
  16. return err == 0
  17. default:
  18. return false
  19. }
  20. }