improve terminfo detection