Add proper terminal and terminfo detection