sshpiper/cmd/sshpiperd/internal/plugin/tty.go
Tommaso Doninelli 69fec645ca
Cross-compatible check if FD is a TTY terminal (#151)
Package `term` provides support functions for dealing with terminals, cross-compatible with Unix,darwin and windows.

 The low leve const `unix.TCGETS` is not defined in Darwin arch, ad prevent shspiper to buil and run on osx
2023-04-06 14:57:24 -07:00

17 lines
286 B
Go

package plugin
import (
"golang.org/x/term"
"io"
"os"
)
// checkIfTerminal returns whether the given file descriptor is a terminal.
func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
return term.IsTerminal(int(v.Fd()))
default:
return false
}
}