From 10ff0d07c31daf527d014cdf950c69b49b081a51 Mon Sep 17 00:00:00 2001 From: Andrey Tcherepanov Date: Tue, 26 Mar 2019 10:19:59 -0600 Subject: [PATCH 1/4] Got rid of IsTerminal call to reduce external dependencies --- terminal_check_aix.go | 10 +++++----- terminal_check_bsd.go | 7 +++++++ terminal_check_linux.go | 7 +++++++ terminal_check_notappengine.go | 8 +++++--- 4 files changed, 24 insertions(+), 8 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 04fdb7b..948c385 100644 --- a/terminal_check_aix.go +++ b/terminal_check_aix.go @@ -1,9 +1,9 @@ -// +build !appengine,!js,!windows,aix +// +build 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 0000000..8f9c330 --- /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 0000000..1690197 --- /dev/null +++ b/terminal_check_linux.go @@ -0,0 +1,7 @@ +// +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 d465565..156a93b 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 } From 7de3dd8c8bcd66620fd36cc2f77c8f3d1508c612 Mon Sep 17 00:00:00 2001 From: Andrey Tcherepanov Date: Tue, 26 Mar 2019 11:01:50 -0600 Subject: [PATCH 2/4] Removed golang.org/x/crypto refs --- .travis.yml | 4 ---- go.mod | 1 - go.sum | 2 -- 3 files changed, 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff85ac7..21c75b7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ matrix: - go: 1.10.x install: - go get github.com/stretchr/testify/assert - - go get golang.org/x/crypto/ssh/terminal - go get golang.org/x/sys/unix - go get golang.org/x/sys/windows script: @@ -22,7 +21,6 @@ matrix: env: GO111MODULE=off install: - go get github.com/stretchr/testify/assert - - go get golang.org/x/crypto/ssh/terminal - go get golang.org/x/sys/unix - go get golang.org/x/sys/windows script: @@ -37,7 +35,6 @@ matrix: env: GO111MODULE=off install: - go get github.com/stretchr/testify/assert - - go get golang.org/x/crypto/ssh/terminal - go get golang.org/x/sys/unix - go get golang.org/x/sys/windows script: @@ -45,7 +42,6 @@ matrix: - go: 1.10.x install: - go get github.com/stretchr/testify/assert - - go get golang.org/x/crypto/ssh/terminal - go get golang.org/x/sys/unix - go get golang.org/x/sys/windows script: diff --git a/go.mod b/go.mod index 94574cc..8261a2b 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,5 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/objx v0.1.1 // indirect github.com/stretchr/testify v1.2.2 - golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 ) diff --git a/go.sum b/go.sum index 133d34a..2d787be 100644 --- a/go.sum +++ b/go.sum @@ -9,7 +9,5 @@ github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= From 41ee4dd36547ea07a3ffc951db6c341988569d5d Mon Sep 17 00:00:00 2001 From: Andrey Tcherepanov Date: Tue, 26 Mar 2019 14:53:49 -0600 Subject: [PATCH 3/4] 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 } From 5d8c3bffc9ce192a8c4f61e46f3f174969149cc6 Mon Sep 17 00:00:00 2001 From: Andrey Tcherepanov Date: Wed, 27 Mar 2019 10:59:38 -0600 Subject: [PATCH 4/4] Updated travis.yml --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 21c75b7..2442f0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,6 @@ matrix: env: GO111MODULE=off install: - go get github.com/stretchr/testify/assert - - go get golang.org/x/crypto/ssh/terminal - go get golang.org/x/sys/unix - go get golang.org/x/sys/windows script: @@ -71,7 +70,6 @@ matrix: env: GO111MODULE=off install: - go get github.com/stretchr/testify/assert - - go get golang.org/x/crypto/ssh/terminal - go get golang.org/x/sys/unix - go get golang.org/x/sys/windows script: