Skip to content

Commit

Permalink
Moved moved unix-related parts into terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
tandr committed Mar 27, 2019
1 parent 1bdda97 commit 9a81d9f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
13 changes: 13 additions & 0 deletions 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
}

13 changes: 13 additions & 0 deletions 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
}

9 changes: 0 additions & 9 deletions terminal_check_aix.go

This file was deleted.

7 changes: 0 additions & 7 deletions terminal_check_bsd.go

This file was deleted.

7 changes: 0 additions & 7 deletions terminal_check_linux.go

This file was deleted.

6 changes: 2 additions & 4 deletions terminal_check_notappengine.go
Expand Up @@ -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
}
Expand Down

0 comments on commit 9a81d9f

Please sign in to comment.