From 41ee4dd36547ea07a3ffc951db6c341988569d5d Mon Sep 17 00:00:00 2001 From: Andrey Tcherepanov Date: Tue, 26 Mar 2019 14:53:49 -0600 Subject: [PATCH] Moved moved unix-related parts into terminal --- internal/terminal/terminal_check_bsd.go | 13 +++++++++++++ internal/terminal/terminal_check_unix.go | 13 +++++++++++++ terminal_check_aix.go | 9 --------- terminal_check_bsd.go | 7 ------- terminal_check_linux.go | 7 ------- terminal_check_notappengine.go | 6 ++---- 6 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 internal/terminal/terminal_check_bsd.go create mode 100644 internal/terminal/terminal_check_unix.go delete mode 100644 terminal_check_aix.go delete mode 100644 terminal_check_bsd.go delete mode 100644 terminal_check_linux.go diff --git a/internal/terminal/terminal_check_bsd.go b/internal/terminal/terminal_check_bsd.go new file mode 100644 index 0000000..6a47df6 --- /dev/null +++ b/internal/terminal/terminal_check_bsd.go @@ -0,0 +1,13 @@ +// +build darwin dragonfly freebsd netbsd openbsd + +package terminal + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TIOCGETA + +func IsTerminal(fd int) bool { + _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + return err == nil +} + diff --git a/internal/terminal/terminal_check_unix.go b/internal/terminal/terminal_check_unix.go new file mode 100644 index 0000000..f30ea87 --- /dev/null +++ b/internal/terminal/terminal_check_unix.go @@ -0,0 +1,13 @@ +// +build linux aix + +package terminal + +import "golang.org/x/sys/unix" + +const ioctlReadTermios = unix.TCGETS + +func IsTerminal(fd int) bool { + _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) + return err == nil +} + diff --git a/terminal_check_aix.go b/terminal_check_aix.go deleted file mode 100644 index 948c385..0000000 --- a/terminal_check_aix.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build aix - -package logrus - -import ( - "golang.org/x/sys/unix" -) - -const ioctlReadTermios = unix.TCGETS diff --git a/terminal_check_bsd.go b/terminal_check_bsd.go deleted file mode 100644 index 8f9c330..0000000 --- a/terminal_check_bsd.go +++ /dev/null @@ -1,7 +0,0 @@ -// +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 deleted file mode 100644 index 1690197..0000000 --- a/terminal_check_linux.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build linux - -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 156a93b..6f28f89 100644 --- a/terminal_check_notappengine.go +++ b/terminal_check_notappengine.go @@ -6,15 +6,13 @@ import ( "io" "os" - "golang.org/x/sys/unix" + "github.com/sirupsen/logrus/internal/terminal" ) func checkIfTerminal(w io.Writer) bool { switch v := w.(type) { case *os.File: - _, err := unix.IoctlGetTermios(int(v.Fd()), ioctlReadTermios) - - return err == nil + return terminal.IsTerminal(int(v.Fd())) default: return false }