1// Based on ssh/terminal:
2// Copyright 2011 The Go Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file.
5
6// +build linux,!appengine darwin freebsd openbsd
7
8package term
9
10import (
11	"io"
12	"syscall"
13	"unsafe"
14)
15
16// IsTerminal returns true if w writes to a terminal.
17func IsTerminal(w io.Writer) bool {
18	fw, ok := w.(fder)
19	if !ok {
20		return false
21	}
22	var termios syscall.Termios
23	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fw.Fd(), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
24	return err == 0
25}
26