Determine if a file descriptor is a terminal in Go
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
.gitignore
Makefile
README.markdown
check.go
check_bsd.go
check_linux.go
isatty.go
stub.go

README.markdown

isatty

-- import "github.com/robertkrimen/isatty"

Package isatty tries to determine if a file descriptor is connected to a terminal.

 import (
     "github.com/robertkrimen/isatty"
     "os"
 )

 func isTerminalStdin() bool {
     return isatty.Check(os.Stdin.Fd())
 }

Originally adapted from: https://code.google.com/p/go/source/browse/ssh/terminal/util.go?repo=crypto

Usage

func CanCheck

func CanCheck() bool

CanCheck will return true if Check is capable of returning a genuine answer.

Darwin (Mac OS X)   CanCheck() => true   # syscall.Syscall6(..., TIOCGETA, ...)
Linux               CanCheck() => true   # syscall.Syscall6(..., TCGETS, ...)
FreeBSD             CanCheck() => true   # syscall.Syscall6(..., TIOCGETA, ...)
Windows             CanCheck() => false  # N/A
(Otherwise)         CanCheck() => false  # N/A

func Check

func Check(fd uintptr) bool

Check will return true if the file descriptor is a terminal and false otherwise.

If Check is unable to determine the terminal status of a file descriptor, then it returns false. This could be the case if this package is used on Windows or an unknown/unconsidered platform.

-- godocdown http://github.com/robertkrimen/godocdown