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.


Update: seems that termios in POSIX now defines a portable interface.