Check output device is a terminal: Difference between revisions

→‎{{header|Go}}: A solution without the use of external libraries. I'm 95% sure this isn't any worse than the previous version (both would have corner cases)
m (Promote to task, lots of examples, little real controversy, most concerns have been addressed)
(→‎{{header|Go}}: A solution without the use of external libraries. I'm 95% sure this isn't any worse than the previous version (both would have corner cases))
Line 235:
 
=={{header|Go}}==
Tells a ''terminal'' apart from a ''pipe'' on Linux and Mac, which is probably exactly what you need.
{{libheader|Go sub-repositories}}
 
<lang go>package main
 
Line 241 ⟶ 242:
"os"
"fmt"
"golang.org/x/crypto/ssh/terminal"
)
 
func main() {
if terminal.IsTerminal(int(fileInfo, _ := os.Stdout.FdStat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
fmt.Println("Hello terminal")
} else {
fmt.Println("Who are you? You're not a terminal.")
}
}</lang>
Line 256:
Hello terminal
> hello | cat
Who are you? You're not a terminal.
</pre>
 
Anonymous user