If you don't use something like ncurses, you will have to do something like the following:
Code:
- Determine how many rows and columns the tty has
- Determine how auto-wrap works on this tty
- Determine how to position the cursor on this tty
- Put the tty into raw mode, no echo
- clear the screen, home the cursor
- save the cursor position as the output cursor
- move the cursor to the bottom line of the screen
- clear the input buffer
- clear the line and display a prompt
- move the cursor to the end of the prompt
- if a message is available to display then
- save the position of the cursor in the input area
- restore the position of the cursor in the output area
- display the new output, handling scrolling of all but the last line of the screen if it is needed
- save the position of the cursor in the output area
- restore the cursor position in the input area
- endif
- if a character has been entered then
- if that character is a newline then
- send the accumulated message from the input area to the chat server
- goto step #7
- else
- append the typed character to the input buffer
- display the entered character in the input area and advance the cursor
- endif
- endif
- goto step #11
I'm assuming that the chat server sends the message back to you as well as to other chatters, otherwise this is more complicated. Also, I'm not adding the complexity of command processing, dealing with input that overflows the width of the screen, editing (delete and stuff like that), and how to clean up when you're done (taking the tty out of raw mode, restoring scrolling regions, etc.)
Also, where I put "goto step #7", in code, you should just duplicate the stuff from steps #7 through #10 (actually, put it in a separate function and call it from both places.)
I've oversimplified the stuff above. Please believe me, you really don't want to do this from scratch.