forked from phuslu/log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_unix.go
69 lines (63 loc) · 1.15 KB
/
console_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//go:build !windows
// +build !windows
package log
import (
"os"
"syscall"
"unsafe"
)
func isTerminal(fd uintptr, os, arch string) bool {
var trap uintptr // SYS_IOCTL
switch os {
case "plan9", "js", "nacl":
return false
case "linux", "android":
switch arch {
case "amd64":
trap = 16
case "arm64":
trap = 29
case "mips", "mipsle":
trap = 4054
case "mips64", "mips64le":
trap = 5015
default:
trap = 54
}
default:
trap = 54
}
var req uintptr // TIOCGETA
switch os {
case "linux", "android":
switch arch {
case "ppc64", "ppc64le":
req = 0x402c7413
case "mips", "mipsle", "mips64", "mips64le":
req = 0x540d
default:
req = 0x5401
}
case "darwin":
switch arch {
case "amd64", "arm64":
req = 0x40487413
default:
req = 0x402c7413
}
default:
req = 0x402c7413
}
var termios [256]byte
_, _, err := syscall.Syscall6(trap, fd, req, uintptr(unsafe.Pointer(&termios[0])), 0, 0, 0)
// println(os, arch, err)
return err == 0
}
// WriteEntry implements Writer.
func (w *ConsoleWriter) WriteEntry(e *Entry) (int, error) {
out := w.Writer
if out == nil {
out = os.Stderr
}
return w.write(out, e.buf)
}