A discussion and an FAQ. Seems that the best bet is ncurses. Or if you want to operate tty directly your code will not be portable.