Last active
June 21, 2022 14:01
-
-
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".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func validTTY() bool { | |
stat, _ := os.Stdout.Stat() | |
if (stat.Mode() & os.ModeCharDevice) == 0 { | |
return false | |
} | |
return true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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