initial commit
[govpp.git] / vendor / github.com / Sirupsen / logrus / terminal_notwindows.go
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         "io"
13         "os"
14         "syscall"
15         "unsafe"
16 )
17
18 // IsTerminal returns true if stderr's file descriptor is a terminal.
19 func 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 }