From 69fec645ca332a58f634bc8e8a9101b86c5252ca Mon Sep 17 00:00:00 2001 From: Tommaso Doninelli Date: Thu, 6 Apr 2023 23:57:24 +0200 Subject: [PATCH] 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 --- cmd/sshpiperd/internal/plugin/tty.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cmd/sshpiperd/internal/plugin/tty.go b/cmd/sshpiperd/internal/plugin/tty.go index 6a739bc0..00420690 100644 --- a/cmd/sshpiperd/internal/plugin/tty.go +++ b/cmd/sshpiperd/internal/plugin/tty.go @@ -1,24 +1,16 @@ package plugin import ( + "golang.org/x/term" "io" "os" - - "golang.org/x/sys/unix" ) -const ioctlReadTermios = unix.TCGETS - -func isTerminal(fd int) bool { - _, err := unix.IoctlGetTermios(fd, ioctlReadTermios) - return err == nil -} - -// code from logrus +// checkIfTerminal returns whether the given file descriptor is a terminal. func checkIfTerminal(w io.Writer) bool { switch v := w.(type) { case *os.File: - return isTerminal(int(v.Fd())) + return term.IsTerminal(int(v.Fd())) default: return false }