terminal_notwindows.go 574 B

12345678910111213141516171819202122
  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. package logrus
  7. import (
  8. "syscall"
  9. "unsafe"
  10. )
  11. // IsTerminal returns true if stderr's file descriptor is a terminal.
  12. func IsTerminal() bool {
  13. fd := syscall.Stderr
  14. var termios Termios
  15. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
  16. return err == 0
  17. }