Browse Source

Moved moved unix-related parts into terminal

tags/v1.4.1
Andrey Tcherepanov 8 months ago
parent
commit
41ee4dd365

+ 13
- 0
internal/terminal/terminal_check_bsd.go View File

@@ -0,0 +1,13 @@
1
+// +build darwin dragonfly freebsd netbsd openbsd
2
+
3
+package terminal
4
+
5
+import "golang.org/x/sys/unix"
6
+
7
+const ioctlReadTermios = unix.TIOCGETA
8
+
9
+func IsTerminal(fd int) bool {
10
+	_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
11
+	return err == nil
12
+}
13
+

+ 13
- 0
internal/terminal/terminal_check_unix.go View File

@@ -0,0 +1,13 @@
1
+// +build linux aix
2
+
3
+package terminal
4
+
5
+import "golang.org/x/sys/unix"
6
+
7
+const ioctlReadTermios = unix.TCGETS
8
+
9
+func IsTerminal(fd int) bool {
10
+	_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
11
+	return err == nil
12
+}
13
+

+ 0
- 9
terminal_check_aix.go View File

@@ -1,9 +0,0 @@
1
-// +build aix
2
-
3
-package logrus
4
-
5
-import (
6
-	"golang.org/x/sys/unix"
7
-)
8
-
9
-const ioctlReadTermios = unix.TCGETS

+ 0
- 7
terminal_check_bsd.go View File

@@ -1,7 +0,0 @@
1
-// +build darwin dragonfly freebsd netbsd openbsd
2
-
3
-package logrus
4
-
5
-import "golang.org/x/sys/unix"
6
-
7
-const ioctlReadTermios = unix.TIOCGETA

+ 0
- 7
terminal_check_linux.go View File

@@ -1,7 +0,0 @@
1
-// +build linux
2
-
3
-package logrus
4
-
5
-import "golang.org/x/sys/unix"
6
-
7
-const ioctlReadTermios = unix.TCGETS

+ 2
- 4
terminal_check_notappengine.go View File

@@ -6,15 +6,13 @@ import (
6 6
 	"io"
7 7
 	"os"
8 8
 
9
-	"golang.org/x/sys/unix"
9
+	"github.com/sirupsen/logrus/internal/terminal"
10 10
 )
11 11
 
12 12
 func checkIfTerminal(w io.Writer) bool {
13 13
 	switch v := w.(type) {
14 14
 	case *os.File:
15
-		_, err := unix.IoctlGetTermios(int(v.Fd()), ioctlReadTermios)
16
-
17
-		return err == nil
15
+		return terminal.IsTerminal(int(v.Fd()))
18 16
 	default:
19 17
 		return false
20 18
 	}

Loading…
Cancel
Save