From 990d24621f8005257e2a4d24066d8a5d36cf0c56 Mon Sep 17 00:00:00 2001 From: Andrey Tcherepanov Date: Tue, 26 Mar 2019 10:19:59 -0600 Subject: [PATCH] Got rid of IsTerminal call to reduce external dependencies --- terminal_check_aix.go | 10 ++++------ terminal_check_bsd.go | 7 +++++++ terminal_check_linux.go | 5 +++++ terminal_check_notappengine.go | 8 +++++--- 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 terminal_check_bsd.go create mode 100644 terminal_check_linux.go diff --git a/terminal_check_aix.go b/terminal_check_aix.go index 04fdb7ba3..18c7b1adb 100644 --- a/terminal_check_aix.go +++ b/terminal_check_aix.go @@ -1,9 +1,7 @@ -// +build !appengine,!js,!windows,aix - package logrus -import "io" +import ( + "golang.org/x/sys/unix" +) -func checkIfTerminal(w io.Writer) bool { - return false -} +const ioctlReadTermios = unix.TCGETS diff --git a/terminal_check_bsd.go b/terminal_check_bsd.go new file mode 100644 index 000000000..8f9c33094 --- /dev/null +++ b/terminal_check_bsd.go @@ -0,0 +1,7 @@ +// +build darwin dragonfly freebsd netbsd openbsd + +package logrus + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TIOCGETA diff --git a/terminal_check_linux.go b/terminal_check_linux.go new file mode 100644 index 000000000..e0fa7d1e8 --- /dev/null +++ b/terminal_check_linux.go @@ -0,0 +1,5 @@ +package logrus + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TCGETS diff --git a/terminal_check_notappengine.go b/terminal_check_notappengine.go index d46556509..156a93b7d 100644 --- a/terminal_check_notappengine.go +++ b/terminal_check_notappengine.go @@ -1,4 +1,4 @@ -// +build !appengine,!js,!windows,!aix +// +build !appengine,!js,!windows package logrus @@ -6,13 +6,15 @@ import ( "io" "os" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/sys/unix" ) func checkIfTerminal(w io.Writer) bool { switch v := w.(type) { case *os.File: - return terminal.IsTerminal(int(v.Fd())) + _, err := unix.IoctlGetTermios(int(v.Fd()), ioctlReadTermios) + + return err == nil default: return false }