Retrieve cursor pos

This is a discussion on Retrieve cursor pos within the Linux Programming forums, part of the Platform Specific Boards category; Our OS is Unixware 7 and we work in a high-level application generating development environment. There is a problem with ...

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Retrieve cursor pos

    Our OS is Unixware 7 and we work in a high-level application generating development environment. There is a problem with it that I am trying to work around. I am considering calling a program with a system call that will simply return the line number that the cursor is on. I have found the curses.h way to determine the line, but it apparently won't work as necessary because it creates a new window with initscr(); so it will always return 0.

    Basically what I need to know if there is any way to retrieve the current line number of the cursor as it exists before running the program (and without modifying the screen contents).

    If you can assist in any way I'd appreciate it. Thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    So what is the program asking "where is the cursor" written in?

    Why isn't it using curses to start with

    Why can't it use curses now?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Perhaps I didn't do a good enough job explaining the problem. The development application/environment is called ProIV (and I'm quite certain no one here has ever heard of it) and that is also the language it is written in. In this environment resides a screen application that displays multiple records on a single screen using one line per record. The way the application populates the screen is it reads each record from disk then displays each and allows the user to arrow the cursor up and down between records on screen without any more file accesses (until the user arrows out of the scope of the screen and another page needs to be displayed). I need to know upon exit of the screen which record the cursor the user has the cursor sitting on but it can't be done programatically from within the screen.

    The only workaround I could fathom is, upon exit of the screen, to run outside of the ProIV environment (with a system call) the program that I am hoping you can help me figure out how to write which will return to the screen application the line number of the cursor so I will then be able to determine which record the user has selected.

    [edit]
    After re-reading your post I realize I seriously overexplained my answer. To re-explain, the program asking where the cursor is is written in ProIV and is a very high-level language and is basically a application generator so it is nothing near a lower level language (such as C++) where I could do such things as locating the cursor with the OS. I can only do what is provided for by ProIV.
    Last edited by LuckY; 11-01-2003 at 12:00 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    My first thought was this, use the ANSI terminal cursor position read function, but it doesn't work as expected (not for me at least). I guess you need a real terminal to be able to intercept the information returned....
    Code:
    #!/bin/bash
    
    # from http://sunsite.nus.edu.sg/pub/os2/os...aq.2.0062.html
    # Escape Code Sequence          Function
    # Cursor Controls
    # ESC[#;#H or ESC[#;#f          Moves cursor to line #, column #
    # ESC[#A                        Moves cursor up # lines
    # ESC[#B                        Moves cursor down # lines
    # ESC[#C                        Moves cursor forward # spaces
    # ESC[#D                        Moves cursor back # spaces
    # ESC[#;#R                      Reports current cursor line and column
    # ESC[s                         Saves cursor position for recall later
    # ESC[u                         Return to saved cursor position
    # Erase Functions
    # ESC[2J                        Clear screen and home cursor
    # ESC[K                         Clear to end of line
    
    # clear screen
    echo -ne "\\e[2J"
    
    # move cursor
    echo -ne "\\e[10;5H"
    
    # print something
    echo -ne "Hello"
    
    # read cursor position - by sending the Device status report
    # see http://vt100.net/docs/vt100-ug/chapter3.html#DSR
    echo -ne "\\e[6n"
    # this 'works', but the result gets printed to the screen!!! (not good)
    Note: this is the bash echo command. The way you generate escape sequences using other echo commands is specific, so you'd need to read up on them if you wanted to try stuff.

    Enough of that, this is plan B
    Code:
    myproIVprog | tee spy
    Try running your proIV program as shown above. If it works, you should find a copy of everything sent to the screen inside the file as well. With a bit of effort, you should be able to spot cursor movements, track them and hence figure out the final cursor position.
    Yes, it's a HACK!!!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    I'm definitely going to give that a try Monday morning (the first option I mean ;P). Thanks a lot Salem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-07-2005, 06:59 AM
  2. retrieve double variable in scanf
    By cfriend in forum C Programming
    Replies: 1
    Last Post: 11-25-2004, 02:53 PM
  3. [code] Enumerate IE instances and retrieve interfaces.
    By anonytmouse in forum Windows Programming
    Replies: 1
    Last Post: 05-05-2004, 08:01 AM
  4. How to retrieve video hardware info
    By MrGrieves in forum Windows Programming
    Replies: 7
    Last Post: 08-01-2002, 01:22 PM
  5. How do i retrieve an X,Y CO_ORD
    By frgmstr in forum Windows Programming
    Replies: 2
    Last Post: 02-13-2002, 07:00 PM

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