Moving the cursor around

This is a discussion on Moving the cursor around within the Linux Programming forums, part of the Platform Specific Boards category; OK, so I've found some of the escape codes to move the cursor around the screen, but I've looked at ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    7

    Moving the cursor around

    OK, so I've found some of the escape codes to move the cursor around the screen, but I've looked at what the escape codes provide, and I cant seem to figure out how I could do what I need it to do.. here is the algorithm...

    User is typing input at the bottom of the screen
    Message arrives
    Insert a blank line 2nd row up from the bottom (everything moves up except for user input)
    Print incoming message above the current user input line
    Return cursor to previous point.

    I dont know if what I want can be done, especially since it seems my terminal doesnt support save/restore cursor positions. If it isnt, does anyone have any way to do what I want (keep input where it is, add a new line from the incoming message). I was thinking ncurses, but it seems so much more complex vs the amount of effort I want to exert for this project (and the time constraints).

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    might want to look into ncurses
    http://www.gnu.org/software/ncurses/ncurses.html

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    7
    Is ncurses the only way you think? It looks quite complex and I really dont have a lot of free time to invest into making it look pretty. I need a quick and dirty solution. Is there any way to get a line of text the user is currently typing? Like get every charecter on the current line w/o having them have to hit enter.

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    not without 3rd party libraries, like ncurses, or a compiler with getch(), etc.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Is there any way to get a line of text the user is currently typing? Like get every charecter on the current line w/o having them have to hit enter.
    Just a couple threads down from this one:
    faq: cached input with mygetch()

  6. #6
    Registered User
    Join Date
    Apr 2004
    Posts
    7
    Hmm... I got it sorta working, using escape codes. The only problem is that when I've inserted the line that came in from another client, I cant figure out how to put the cursor back in the correct column. I tell it to move to the first col in row 1, but I cant figure out a way to put it at the end of the user's input. My proof of concept code is as follows.

    Code:
    #include <stdio.h>
    
    int main() {
    
      printf("\033[2J"); /*clear screen*/
      printf("\033[2;1H"); /*put in seperator between User input and chat text*/
      printf("-----------------------------\n"); /*barrier*/
      printf("\033[1;1H"); /*put at upper left*/
      printf(">some user text not done yet... "); /*user is in the middle of typing*/
    
      printf("\033[3;1H"); /*move to 2nd line on screen*/
      printf("\033[1L"); /*insert line here*/
      printf("comment one\n"); /*some text arrives*/
      printf("\033[1;1H"); /*go back to first row*/
      printf("\033[4~"); /*supposed to be "END" key but doesnt work (hitting the end key doesnt seem to work either, so I dont know what to put here)*/
      printf("more text... ");
    
      printf("\033[3;1H"); /*move to 2nd line on screen*/
      printf("\033[1L"); /*insert line here*/
      printf("comment two\n"); /*some more text arrives*/
      printf("\033[1;1H"); /*go back to first row*/
      printf("\033[4~"); /*supposed to be "END" key but doesnt work (hitting the end key doesnt seem to work either, so I dont know what to put here)*/
    
      char ui[255];
    
      fgets(ui, 255, stdin);
      printf("%s\n", ui);
    
      return 0;
      
    }

  7. #7
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Quote Originally Posted by doormat
    Is ncurses the only way you think? It looks quite complex and I really dont have a lot of free time to invest into making it look pretty......
    Actually it's not really hard as it possibly looks like at first sight.
    Check: http://www.tldp.org/HOWTO/NCURSES-Pr...WTO/index.html
    This is kind a good document to start using / learn ncurses, atleast for me it didn't cause any pains.
    ncurses just makes it easy to manipulate whole window, taking inputs from mouse / keyboard, move cursor anywhere on window etc....





    -- 1. weekend with ncurses --

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. moving median function
    By supermeew in forum C Programming
    Replies: 0
    Last Post: 05-04-2006, 02:37 PM
  3. Replies: 4
    Last Post: 01-16-2006, 04:58 PM
  4. 3D moving
    By bluehead in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2005, 04:46 AM
  5. Simple program i cant get (dot moving)
    By Lupusk9 in forum C++ Programming
    Replies: 4
    Last Post: 09-14-2004, 08:04 PM

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