6.6 Cursor Movement

In the UNIX system environment, you can use Curses functions to move the cursor across the terminal screen. With other implementations, you can either allow Curses to move the cursor using the move function, or you can specify the origin and the destination of the cursor to the mvcur function, which moves the cursor in a more efficient manner.

In DEC C for OpenVMS Systems, the two functions are functionally equivalent and move the cursor with the same efficiency.

Example 6-5 shows how to use the move and mvcur functions.

Example 6-5 The Cursor Movement Functions

#include <curses.h>

main()
{
   initscr();
      .
      .
      .
    clear();
    move(10, 10);
    move(LINES/2, COLS/2);
    mvcur(0, COLS-1, LINES-1, 0);
      .
      .
      .
   endwin();
}

Key to Example 6-5:

  1. The clear macro erases stdscr and positions the cursor at coordinates (0,0).

  2. The first occurrence of move moves the cursor to coordinates (10,10).

  3. The second occurrence of move uses the predefined variables LINES and COLS to calculate the center of the screen (by calculating the value of half the number of LINES and COLS on the screen).

  4. The mvcur function forces absolute addressing. This function can address the lower left corner of the screen by claiming that the cursor is presently in the upper right corner. You can use this method if you are unsure of the current position of the cursor, but move works just as well.


Previous Page | Next Page | Table of Contents | Index