blob: 190297abf3803502c8c3364df454798855d527cd [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// 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
9package logrus
10
11import (
12 "io"
13 "os"
14 "syscall"
15 "unsafe"
16)
17
18// IsTerminal returns true if stderr's file descriptor is a terminal.
19func IsTerminal(f io.Writer) bool {
20 var termios Termios
21 switch v := f.(type) {
22 case *os.File:
23 _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(v.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
24 return err == 0
25 default:
26 return false
27 }
28}