This uses ioctl syscalls or appropriate alternative, to detect if stdin/out/err are character devices or not. This caches the result, to ensure performance is ok at runtime as executing stat can approach microsecond overhead. Signed-off-by: Adrian Cole <adrian@tetrate.io>
15 lines
293 B
Go
15 lines
293 B
Go
package platform
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
var procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
|
|
|
|
func isTerminal(fd uintptr) bool {
|
|
var st uint32
|
|
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0)
|
|
return r != 0 && e == 0
|
|
}
|