Files
mc/pkg/console/isatty_linux.go
T
Harshavardhana 6d4a7c5e7b Add function isatty() to detect if Stdout for console is a terminal, if not disable coloring - fixes #631
Necessary when one has to pipe ``mc`` output to non terminal applications like ``less`` ``more`` etc.
2015-05-16 18:11:56 -07:00

19 lines
450 B
Go

// +build linux
package console
import (
"syscall"
"unsafe"
)
// Standard ioctls from Linux - /usr/include/asm-generic/ioctls.h:#define TCGETS 0x5401
const ioctlReadTermios = syscall.TCGETS
// isatty return true if the file descriptor is terminal.
func isatty(fd uintptr) bool {
var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
}