Skip to content

Commit

Permalink
Got rid of IsTerminal call to reduce external dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tandr committed Mar 26, 2019
1 parent dae0fa8 commit 990d246
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
10 changes: 4 additions & 6 deletions 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
7 changes: 7 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions terminal_check_linux.go
@@ -0,0 +1,5 @@
package logrus

import "golang.org/x/sys/unix"

const ioctlReadTermios = unix.TCGETS
8 changes: 5 additions & 3 deletions terminal_check_notappengine.go
@@ -1,18 +1,20 @@
// +build !appengine,!js,!windows,!aix
// +build !appengine,!js,!windows

package logrus

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
}
Expand Down

0 comments on commit 990d246

Please sign in to comment.