terminal_notwindows.go 670 B

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