From 6fc776b92457b982c6c9ca4e48027a954dc70780 Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Sat, 11 Jan 2020 23:06:59 +0100 Subject: [PATCH] Exit is stdin is not a tty --- main.go | 5 ++++- pty_master.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 0d8b1bd..a151e5f 100644 --- a/main.go +++ b/main.go @@ -45,7 +45,10 @@ func main() { log.Out = logFile } - // TODO: check we are running inside a tty environment, and exit if not + if !isStdinTerminal() { + fmt.Printf("Input not a tty\n") + os.Exit(1) + } var rawConnection io.ReadWriteCloser if *useTLS { diff --git a/pty_master.go b/pty_master.go index ede291f..296dceb 100644 --- a/pty_master.go +++ b/pty_master.go @@ -26,6 +26,10 @@ func ptyMasterNew() *ptyMaster { return &ptyMaster{} } +func isStdinTerminal() bool { + return terminal.IsTerminal(0) +} + func (pty *ptyMaster) Start(command string, args []string, winChangedCB onWindowChangesCB) (err error) { pty.windowChangedCB = winChangedCB