linux console "window"

This is a discussion on linux console "window" within the Linux Programming forums, part of the Platform Specific Boards category; I'm writing a really simple console chat client for a chat server I wrote. Basicly, what I need is a ...

  1. #1
    puu
    puu is offline
    Registered User
    Join Date
    Dec 2005
    Posts
    4

    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
    Location
    The edge of the known universe
    Posts
    32,821
    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
    Posts
    416
    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
    Location
    West Virginia
    Posts
    235
    If you don't use something like ncurses, you will have to do something like the following:
    Code:
    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
    puu
    puu is offline
    Registered User
    Join Date
    Dec 2005
    Posts
    4
    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.

    EDIT:
    now I have come this far:

    buffer=field(field[0],0);

    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 Cprogramming.com
    Replies: 28
    Last Post: 10-05-2006, 07:48 PM
  2. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 03: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, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21