Skip to content

robertkrimen/isatty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Determine if a file descriptor is a terminal in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages