Add better xterm detection and SSH detection