Skip to content

ifrstr/isatty

Repository files navigation

isatty

Go Reference Go Report Card

Determine whether the stream is a tty.

Features

  • Supports most platforms

  • Supports force override using environment variable FORCE_TTY

Install

go get gopkg.ilharper.com/x/isatty

Usage

import "gopkg.ilharper.com/x/isatty"

if isatty.Isatty(os.Stdout.Fd()) {
	// TTY
} else {
	// Not TTY
}

Go Reference

Using FORCE_TTY

User can override the result using the environment variable FORCE_TTY.

# Force TTY
FORCE_TTY=
FORCE_TTY=1
FORCE_TTY=true

# Force not TTY
FORCE_TTY=0
FORCE_TTY=false

Test

To determine whether the current stdout is a tty:

go test

Defects on Windows

See #3.

LICENSE

MIT