Thread: linux console "window"

  1. #1
    Registered User
    Join Date
    Dec 2005

    linux console "window"

    I'm writing a really simple console chat client for a chat server I wrote. Basicly, what I need is a line at the bottom for user input and the rest for text coming from the server. I tried something with ncurses, but it was a bit too complex for now.

    The client I have written this far dumps everything in stdout and that's inconvenient for many reasons. It gets the input from a separate thread.

    I'm grateful for any suggestions and ideas.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Practice using ncurses in another program which you can test your knowledge of ncurses, and experiment with new ideas.

    Then when you know some stuff, put that to use in your chat program.

  3. #3
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    as well, you can look at apps like licq a console icq client.
    see how they designed the interface, and how well it functions.
    then get ideas from it for your own app.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  4. #4
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    West Virginia
    If you don't use something like ncurses, you will have to do something like the following:
    1. Determine how many rows and columns the tty has
    2. Determine how auto-wrap works on this tty
    3. Determine how to position the cursor on this tty
    4. Put the tty into raw mode, no echo
    5. clear the screen, home the cursor
    6. save the cursor position as the output cursor
    7. move the cursor to the bottom line of the screen
    8. clear the input buffer
    9. clear the line and display a prompt
    10. move the cursor to the end of the prompt
    11. if a message is available to display then
    12. save the position of the cursor in the input area
    13. restore the position of the cursor in the output area
    14. display the new output, handling scrolling of all but the last line of the screen if it is needed
    15. save the position of the cursor in the output area
    16. restore the cursor position in the input area
    17. endif
    18. if a character has been entered then
    19. if that character is a newline then
    20. send the accumulated message from the input area to the chat server
    21. goto step #7
    22. else
    23. append the typed character to the input buffer
    24. display the entered character in the input area and advance the cursor
    25. endif
    26. endif
    27. 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.
    Last edited by filker0; 12-13-2005 at 10:40 AM. Reason: fix typing error
    Insert obnoxious but pithy remark here

  5. #5
    Registered User
    Join Date
    Dec 2005
    I decided to go with ncurses with forms(forms.h). This brought me a new problem: I know how to set a field buffer and I know how to get one, but I have no clue about how to assign anything I write to the buffer. When I type something, it shows in the field at the bottom of the window, but anything beyond that is pretty much a mystery to me.

    now I have come this far:


    this should, according to the man pages, set the "buffer" to whatever is written in field[0], but all I get is buffer filled with whitespaces with the length of what is written in field[0].
    Last edited by puu; 12-14-2005 at 07:09 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux Version reccomendation
    By Pobega in forum A Brief History of
    Replies: 28
    Last Post: 10-05-2006, 06:48 PM
  2. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  3. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  4. cd command in linux console
    By TheUnheardHuman in forum Tech Board
    Replies: 2
    Last Post: 11-19-2002, 03:59 PM
  5. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 08:18 AM