-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput_unix.go
More file actions
22 lines (19 loc) · 595 Bytes
/
Copy pathoutput_unix.go
File metadata and controls
22 lines (19 loc) · 595 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//go:build !windows
package main
import (
"syscall"
"unsafe"
)
// ---- TTY detection (DR-006) -----------------------------------------------
// isTerminal reports whether fd refers to a terminal. Implemented with a
// single syscall rather than a third-party isatty library (DR-001).
func isTerminal(fd uintptr) bool {
var termios [256]byte // large enough for any termios struct on Linux/macOS
_, _, errno := syscall.Syscall(
syscall.SYS_IOCTL,
fd,
syscall.TIOCGWINSZ, // works on both Linux and macOS to probe a TTY
uintptr(unsafe.Pointer(&termios[0])),
)
return errno == 0
}