This implementation is cleaner, even though it does the 'if tty' test twice