Fix tty detection for terminal codes.