Got rid of IsTerminal call to reduce external dependencies

This commit is contained in:
Andrey Tcherepanov 2019-03-26 10:19:59 -06:00
parent 1115b87d62
commit 10ff0d07c3
4 changed files with 24 additions and 8 deletions

View File

@ -1,9 +1,9 @@
// +build !appengine,!js,!windows,aix // +build aix
package logrus package logrus
import "io" import (
"golang.org/x/sys/unix"
)
func checkIfTerminal(w io.Writer) bool { const ioctlReadTermios = unix.TCGETS
return false
}

7
terminal_check_bsd.go Normal file
View File

@ -0,0 +1,7 @@
// +build darwin dragonfly freebsd netbsd openbsd
package logrus
import "golang.org/x/sys/unix"
const ioctlReadTermios = unix.TIOCGETA

7
terminal_check_linux.go Normal file
View File

@ -0,0 +1,7 @@
// +build linux
package logrus
import "golang.org/x/sys/unix"
const ioctlReadTermios = unix.TCGETS

View File

@ -1,4 +1,4 @@
// +build !appengine,!js,!windows,!aix // +build !appengine,!js,!windows
package logrus package logrus
@ -6,13 +6,15 @@ import (
"io" "io"
"os" "os"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/sys/unix"
) )
func checkIfTerminal(w io.Writer) bool { func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) { switch v := w.(type) {
case *os.File: case *os.File:
return terminal.IsTerminal(int(v.Fd())) _, err := unix.IoctlGetTermios(int(v.Fd()), ioctlReadTermios)
return err == nil
default: default:
return false return false
} }