kristofer sweger Home
ANSIPLUS Home


Cursor Positioning

Esc [!#v  Select video page
Esc [!#U  Select next page
Esc [!#V  Select preceding page

The Esc [!v control sequence sets the current video display page directly. One parameter is accepted: the desired page number. If no parameter is supplied, page 0 is selected.

The Esc [#U escape sequence selects a page with a higher number than the current display page. If a parameter is supplied, its value is added to the current page number. If the parameter is omitted, a value of one is added.

Esc [#V selects a page with a lower number than the current display page. If a parameter is supplied, its value is subtracted from the page number; otherwise, a value of one is subtracted.

Some video display controller BIOSes may not implement display page selection correctly for all text display modes (Perhaps this was never tested?). And some Windows display drivers (eg., 256-color Tseng ET-4000) may not allow selecting a display page other than 0 or 1 when running in a Window. The ANSIPLUS driver has no way of detecting these cases in advance, so be careful.

Esc [#;#H  Set cursor position
Esc [#;#f  Set cursor position

Like the DOS ANSI.sys driver, ANSIPLUS sets the cursor position on the current display page with the Esc [H (or the equivalent Esc [f ) control sequence. Two parameters are accepted: the row number and the column number. If either (or both) is omitted, a value of 1 is assumed. For example:

Esc [H Move the cursor to line 1, column 1
Esc [12H Move the cursor to line 12, column 1
Esc [6;41H Move the cursor to line 6, column 41

Esc [#A  Move cursor up
Esc [#B  Move cursor down
Esc [#C  Move cursor right
Esc [#D  Move cursor left

The cursor can be moved up, down, right or left with the Esc [A, Esc [B, Esc [C and Esc [D control sequences, respectively. These all accept one parameter, which is the number of rows or columns to move. If the parameter is omitted, a value of 1 is assumed. For example:

Esc [A Move the cursor up one line, leaving the column unchanged
Esc [3B Move the cursor down 3 lines, keeping the same column
Esc [6C Move the cursor to line 6, keeping the same column

Esc [#E  Move cursor to next line
Esc [#F  Move cursor to preceding line

The Esc [E control sequence moves the cursor to the first column on the next line. If a parameter is supplied, the cursor moves down by the number of lines requested by the parameter. Esc [F moves the cursor to the first column on the preceding line, and if a parameter is supplied, the cursor moves up by the number of lines in the parameter. For example:

Esc [E Move the cursor to column 1 on the next line
Esc [2F Move the cursor to column 1, 2 lines above the current line

Esc [#G  Move cursor to absolute column in same line
Esc [#a  Move cursor to absolute row in same column

The Esc [G control sequence moves the cursor to the column requested by the parameter. The line is unchanged. Esc [a moves the cursor to the line requested by its parameter, and the column is unchanged. For example:

Esc [G Move the cursor to column 1 of the current line
Esc [12G Move the cursor to column 12 on the same line
Esc [6a Move the cursor to line 6, keeping the same column

Esc [#;#;#g  Reset tabs

The Esc [g control sequence clears and optionally re-initializes tab stops. The action taken depends on the value of the first parameter, which selects the function to perform (see table below). A second (or third) optional parameter is accepted for functions 2 to 4, which specifies the interval for setting tabs after they have all been cleared. For example:

Esc [g Clear horizontal tab at the cursor position
Esc [1g Clear vertical tab at the cursor position
Esc [2;8;4g Clear all tabs, then set horizontal tabs every 8 columns and vertical tabs every 4 lines
Esc [3g Clear all horizontal tabs
Esc [4;4g Clear all vertical tabs, then set vertical tabs every 4 lines

Reset Tabs Function Selectors
Selector Function Performed
0 Clear single horizontal tab at cursor location
1 Clear single vertical tab at cursor location
2 Reset all horizontal and vertical tabs
3 Reset all horizontal tabs
4 Reset all vertical tabs


Esc [#;...#W  Tab control

The Esc [W control sequence sets and clears tab stops. The action taken depends on the value of the first parameter, which selects the function to perform (see table below). A variable number of optional parameters are accepted for functions 0 to 3, with each one specifying the line or column to set or clear a tab stop. If no optional parameters are included, the cursor position is assumed. For example:

Esc [W Set horizontal tab at the cursor position
Esc [1;20W Set vertical tab on line 20
Esc [2;9;49W Clear horizontal tabs in columns 9 and 49
Esc [3W Clear vertical tab at the cursor position
Esc [5W Clear all horizontal tabs

Tab Control Function Selectors
Selector
Function Performed
0 Set single horizontal tab
1
Set single vertical tab
2
Clear single horizontal tab
3
Clear single vertical tab
4
Clear all horizontal and vertical tabs
5
Clear all horizontal tabs
6
Clear all vertical tabs


Esc [#I  Horizontal tab
Esc [#Y  Vertical tab
Esc [#Z  Backward tab

The Esc [I, Esc [Y, and Esc [Z control sequences move the cursor to tab stops. Each accepts a single parameter, which is the number of tab stops to count before stopping. If no parameter is included, the count is one. If no tab stop is found, the cursor will not move. For example:

Esc [I Move to the next horizontal tab stop
Esc [3I Move to the third horizontal tab stop to the right of the cursor position
Esc [Y Move the cursor to line 6, keeping the same column
Esc [2Z Move to the second horizontal tab stop to the left of the cursor

Esc [#;#s  Save cursor or other context
Esc [#;#u Restore cursor or other context

ANSIPLUS maintains a small internal storage area (with a capacity of approximately 25 items, configurable for more) for saving and restoring driver context. This storage area is accessed by the Esc [s control sequence to save driver context and Esc [u to restore it.

The action of Esc [s depends on the number of parameters supplied. If there are none, the current cursor location will be saved, providing compatibility with the MS-DOS ANSI.sys Esc [s escape sequence. If a single parameter is supplied, it selects the driver context item to be saved, using the item codes in the table to the right. For either zero or one parameters, the item is saved as though the storage area were a stack: multiple items of the same type can be saved, and the item most recently saved is restored first. If the storage area overflows because of too many saves, the oldest items will be lost.

Driver Context Item Codes
Code
Context Item
0 Cursor location
1
Cursor location (same as 0)
2
Foreground and background colors
3
Current video page
4
Video mode and character height
5
Current scrolling region
6
Current key reassignments
7
Current scroll-back addition point
8
All current ANSIPLUS feature settings
255
Clear the video context storage area

If a second parameter is supplied, it represents a user-defined tag or identifier for directly accessing the item when it is to be restored. The tag may have any value from 1 to 255. Tags make it possible, for example, to save multiple cursor positions and later select which one to restore. Since tagged items are stored for random access, rather than in a stack, any item saved with a tag will replace any previously saved item of the same type with the same tag. Tagged items are never deleted from the driver context storage area until it overflows and more recently saved items push them off the bottom.

The Esc [u control sequence restores driver context items. If no parameter is supplied, the top untagged item on the ANSIPLUS driver context stack, whatever it may be, is restored and deleted from the storage area. If a single parameter is supplied, the topmost item that matches the selected type code is popped from the stack.

If a second (i.e., tag) parameter is supplied, the stored item of the selected type that matches the tag will be restored (but not deleted). If no matching item is found, no restoration will occur.

The following examples should help make this clearer:

Esc [s Save the cursor position
Esc [2s Save the current foreground and background color selection
Esc [4;83s Save the video mode and character height, tagged as number 83
Esc [6s Save all current key reassignments, and allow local additions and/or deletions to the key reassignment tables
Esc [u Restore the most recently saved, untagged item
Esc [2u Restore the most recently saved foreground and background colors
Esc [4;83u Restore the video mode and character height tagged as number 83
Esc [6u Restore the key reassignments, discarding any changes since key reassignments were last saved

© Copyright 2000-2007, Kristofer Sweger. All rights reserved.
Rev. 9/28/19