Jonathan Hart | f86817b | 2018-08-17 10:35:54 -0700 | [diff] [blame^] | 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 | |
| 6 | // +build linux darwin freebsd openbsd netbsd dragonfly |
| 7 | // +build !appengine |
| 8 | |
| 9 | package logrus |
| 10 | |
| 11 | import ( |
| 12 | "syscall" |
| 13 | "unsafe" |
| 14 | ) |
| 15 | |
| 16 | // IsTerminal returns true if stderr's file descriptor is a terminal. |
| 17 | func IsTerminal() bool { |
| 18 | fd := syscall.Stderr |
| 19 | var termios Termios |
| 20 | _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) |
| 21 | return err == 0 |
| 22 | } |