Task

Demonstrate how to check whether the input device is a terminal or not.



Related task

   Check output device is a terminal


package main
 
import (
    "golang.org/x/crypto/ssh/terminal"
    "fmt"
    "os"
)
 
func main() {
    if terminal.IsTerminal(int(os.Stdin.Fd())) {
        fmt.Println("Hello terminal")
    } else {
        fmt.Println("Who are you?  You're not a terminal.")
    }
}