Move tty handling into its own source file.
Allow running without a TTY