Improved detection of terminal output.