diff --git a/tty_bsd.go b/tty_bsd.go index 5067564..d9881ce 100644 --- a/tty_bsd.go +++ b/tty_bsd.go @@ -7,15 +7,18 @@ import ( "unsafe" ) +// IsTty checks if the given fd is a tty func IsTty(fd uintptr) bool { var termios syscall.Termios _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TIOCGETA), uintptr(unsafe.Pointer(&termios)), 0, 0, 0) return err == 0 } +// TtyReady checks if the tty is ready to go func TtyReady() error { return nil } +// TtyTerm restores any state, if necessary func TtyTerm() { } diff --git a/tty_posix.go b/tty_posix.go index e67711f..a4a7bde 100644 --- a/tty_posix.go +++ b/tty_posix.go @@ -7,15 +7,18 @@ import ( "unsafe" ) +// IsTty checks if the given fd is a tty func IsTty(fd uintptr) bool { var termios syscall.Termios _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0) return err == 0 } +// TtyReady checks if the tty is ready to go func TtyReady() error { return nil } +// TtyTerm restores any state, if necessary func TtyTerm() { } diff --git a/tty_windows.go b/tty_windows.go index 4da3f1e..8e144e6 100644 --- a/tty_windows.go +++ b/tty_windows.go @@ -28,6 +28,7 @@ func setStdHandle(stdhandle int32, handle syscall.Handle) error { return nil } +// IsTty checks if the given fd is a tty func IsTty(fd uintptr) bool { f := syscall.MustLoadDLL("kernel32.dll").MustFindProc("GetConsoleMode") var st uint32 @@ -38,6 +39,7 @@ func IsTty(fd uintptr) bool { var stdout = os.Stdout var stdin = os.Stdin +// TtyReady checks if the tty is ready to go func TtyReady() error { var err error _stdin, err := os.Open("CONIN$") @@ -69,6 +71,7 @@ func TtyReady() error { return nil } +// TtyTerm restores any state, if necessary func TtyTerm() { os.Stdin = stdin syscall.Stdin = syscall.Handle(os.Stdin.Fd())