Escape Sequence

From VSI OpenVMS Wiki
Jump to: navigation, search

An escape sequence is a combination of characters that signifies a command for the terminal rather than a literal combination of characters. In terminals that respond to ANSI character sequences, the escape character has the ASCII value of hexadecimal 1B, octal 33, or decimal 27. A symbol for the escape character can be defined as follows:

esc[0,7] = 27

or:

esc[0,8]=%x1B

Control Sequences

Examples in the following tables use the following symbols:

esc[0,7] = 27
text="Text to be displayed"

Character attributes

Description Syntax Example
Bold [1m
write sys$output "''esc'[1m''text'''esc'[m"
 
Underscore [4m
write sys$output "''esc'[4m''text'''esc'[m"
 
Blink [5m
write sys$output "''esc'[4m''text'''esc'[m"
 
Reverse video [7m
write sys$output "''esc'[7m''text'''esc'[m"
 
All attributes off [0m
write sys$output "''esc'[0m''text'''esc'[m"
 

Line Size

The attributes below are valid only for the current line.

Description Syntax Example
Double-height top half #3 Used with #4 to display double-height text:
$ pipe  w "''esc'#3''text'''esc'#3" ; w "''esc'#4''text'''esc'#4"
 
Double-height bottom half #4 Used with #3 to display double-height text:
$ pipe  w "''esc'#3''text'''esc'#3" ; w "''esc'#4''text'''esc'#4"
 
Single width/single height #5
$ w "''esc'#5''text'''esc'#5"
 
Double width/double height #6
$ w "''esc'#6''text'''esc'#6"
 

Erasing

Description Syntax Example
Erases from cursor to end of line [K
Erases from the beginning of line to cursor [1K
$ write sys$output "''esc'[1K"
 
Erases the line containing cursor [2K
$ write sys$output "''esc'[2K"
 
Erases from the cursor to end of screen [J
$ write sys$output "''esc'[J"
 
From beginning of screen to cursor 1J
$ write sys$output "''esc'1J"
 
Erase the entire screen [2J
$ write sys$output "''esc'[2J"
 

$ </nowiki>

Cursor Positioning

Description Syntax Example
Move the cursor to line Pl and column Pc [Pl;PcH or ESC[Pl;Pcf
$ write sys$output "''esc'[0;0H"
 
Cursor up Pn positions [PnA
$ write sys$output "''esc'[1A''text'"
 
Cursor down Pn positions [PnB
$ write sys$output "''esc'[1B''text'"
 
Save cursor and attributes 7
$ write sys$output "''esc'[1B''esc'7"
 
Cursor forward Pn spaces [PnC
$ write sys$output "''esc'[2C''text'"
 
Cursor backward Pn spaces [PnD
$ write sys$output "''esc'[2C''text'"
 
Next line E
$ write sys$output "''text'''esc'E''text'"
 
Restore cursor and attributes ESC 8
$ write sys$output "''esc'[1B''esc'8"
 

Scrolling Region

The scrolling region can be established with escape code [Pt;Pbr, where Pt is the top line of the scrolling region and Pb is the bottom line.

Colors

Description Syntax Example
Reset (resets the color to default) [0m
$ write sys$output  "''esc'[30m''text'''esc'[0m"
 
Black [30m
$ write sys$output  "''esc'[30m''text'''esc'[0m"
 
Red [31m
$ write sys$output  "''esc'[31m''text'''esc'[0m"
 
Green [32m
$ write sys$output  "''esc'[32m''text'''esc'[0m"
 
Yellow [33m
$ write sys$output  "''esc'[33m''text'''esc'[0m"
 
Blue [34m
$ write sys$output  "''esc'[34m''text'''esc'[0m"
 
Magenta [35m
$ write sys$output  "''esc'[35m''text'''esc'[0m"
 
Cyan [36m
$ write sys$output  "''esc'[36m''text'''esc'[0m"
 
White [37m
$ write sys$output  "''esc'[37m''text'''esc'[0m"