talira

go-isatty

isatty for Go: tell whether output goes to a terminal

open sourceMITfree

go-isatty is Yasuhiro Matsumoto's small Go package that tells whether a file descriptor is a terminal: isatty.IsTerminal(os.Stdout.Fd()), plus IsCygwinTerminal for Cygwin and MSYS2 terminals on Windows.

Problems it solves

  • check whether stdout is a terminal in Go before printing colours
  • detect when my Go CLI's output is piped to a file
  • detect a Cygwin or MSYS2 terminal from Go on Windows

Features

  • IsTerminal check for a file descriptor
  • IsCygwinTerminal for Cygwin and MSYS2 terminals
  • no setup beyond go get

Alternatives

The same job

These do what go-isatty does.

  1. color (Go) Coloured terminal output for Go with ANSI escape codes

Compare go-isatty with the top 3