Added support for detecting a tty.