Skip to content

Instantly share code, notes, and snippets.

@kwilczynski
Last active June 21, 2022 14:01
Show Gist options
  • Save kwilczynski/f6a3cc7fbd30dd469e5b7049b386801e to your computer and use it in GitHub Desktop.
Save kwilczynski/f6a3cc7fbd30dd469e5b7049b386801e to your computer and use it in GitHub Desktop.
Check if a TTY is a valid device aka "check if we are run interactively".
func validTTY() bool {
stat, _ := os.Stdout.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
return false
}
return true
}
import "golang.org/x/term"
if term.IsTerminal(int(os.Stdout.Fd())) {
return true
}
return false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment