Codebase list golang-github-go-kit-kit / eb8486a6-f182-4772-872e-3e24b6b63e39/main log / term / terminal_notwindows.go
eb8486a6-f182-4772-872e-3e24b6b63e39/main

Tree @eb8486a6-f182-4772-872e-3e24b6b63e39/main (Download .tar.gz)

terminal_notwindows.go @eb8486a6-f182-4772-872e-3e24b6b63e39/mainraw · history · blame

// Based on ssh/terminal:
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build linux,!appengine darwin freebsd openbsd

package term

import (
	"io"
	"syscall"
	"unsafe"
)

// IsTerminal returns true if w writes to a terminal.
func IsTerminal(w io.Writer) bool {
	fw, ok := w.(fder)
	if !ok {
		return false
	}
	var termios syscall.Termios
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fw.Fd(), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
	return err == 0
}