istty

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2020 License: MIT, MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCygwinPty

func IsCygwinPty(fd uintptr) bool

IsCygwinPty returns true if the file descriptor is a Cygwin/MSYS pty.

Types

type TTYState

type TTYState int
const (
	IsUnknown TTYState = 0
	IsTTY     TTYState = 1
	IsPipe    TTYState = 2
)

func CheckTTY

func CheckTTY(v interface{}) TTYState

isTTY tries to only return true if the input is actually a terminal.

os.ModeCharDevice isn't quite enough. I tested various OS/shell combos, using the following code:

fi, _ := os.Stdin.Stat()
fmt.Println(fi.Mode())

Results:

                TTY in       Pipe in      TTY out      Pipe out
macOS/bash      Dcrw--w----  -prw-rw----  Dcrw--w----  -prw-rw----
macOS/zsh       Dcrw--w----  -prw-rw----  Dcrw--w----  -prw-rw----
linux/bash      Dcrw--w----  -prw-------  Dcrw--w----  -prw-------
linux/zsh       Dcrw--w----  -prw-------  Dcrw--w----  -prw-------
linux/fish      Dcrw--w----  -prw-------  Dcrw--w----  -prw-------
win/cmd.exe     Dcrw-rw-rw-  --rw-rw-rw-  Dcrw-rw-rw-  --rw-rw-rw-
win/powershell  Dcrw-rw-rw-  --rw-rw-rw-  Dcrw-rw-rw-  --rw-rw-rw-
win/gitbash     -prw-rw-rw-  -prw-rw-rw-  -prw-rw-rw-  -prw-rw-rw-
win/cygwin      -prw-rw-rw-  -prw-rw-rw-  -prw-rw-rw-  -prw-rw-rw-

More info:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL