DEFINITION MODULE VT100; (* The POSIX function cfmakeraw() sets the canonical combination. Applications typically use tcgetattr() to save the current settings, call cfmakeraw() to switch to raw mode, and call tcsetattr() with the saved settings on exit to restore the terminal. *) TYPE screenModes = (M40x25BW,M40x25C,M80x25BW,M80x25C,M320x200C4,M320x200BW,M640x200BW, M320x200C256,M640x200C,M640x350BW,M640x350C,M640x480BW,M640x480C,M320x200C); Attribut = (boldAt,dimAt,italicAt,underlineAt,blinkingAt,inverseAt,hiddenAt, strikethroughAt,doubleunderlineAt); Colors = (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, Default, BrightBlack, BrightRed, BrightGreen, BrightYellow, BrightBlue, BrighMagenta, BrightCyan, BrightWhite); (* ESC Code Sequence Reset Sequence Description ESC[1;34;{...}m Set graphics modes for cell, separated by semicolon (;). ESC[1m ESC[22m set bold mode. ESC[2m ESC[22m set dim/faint mode. ESC[3m ESC[23m set italic mode. ESC[4m ESC[24m set underline mode. ESC[5m ESC[25m set blinking mode ESC[7m ESC[27m set inverse/reverse mode ESC[8m ESC[28m set hidden/invisible mode ESC[9m ESC[29m set strikethrough mode. ESC[21m ESC[24m set double underline *) PROCEDURE modesoff; (*OK*) (* SGR0 Turn off character attributes ^[[m *) PROCEDURE modesoff1; (*OK*) (* SGR0 Turn off character attributes ^[[0m *) PROCEDURE bold; (*OK*) (* SGR1 Turn bold mode on ^[[1m *) PROCEDURE lowint; (*OK*) (* SGR2 Turn low intensity mode on ^[[2m *) PROCEDURE italic; (*OK*) (* set italic mode ESC[3m *) PROCEDURE underline; (*OK*) (* SGR4 Turn underline mode on ^[[4m *) PROCEDURE blink; (*OK*) (* SGR5 Turn blinking mode on ^[[5m *) PROCEDURE reverse; (*OK*) (* SGR7 Turn reverse video on ^[[7m *) PROCEDURE invisible; (*OK*) (* SGR8 Turn invisible text mode on ^[[8m *) PROCEDURE strikethrough; (*OK*) (* ESC[9m ESC[29m set strikethrough mode. *) PROCEDURE doubleUnderline; (* ESC[21m *) PROCEDURE resetbold; (*OK*) (* SGR1 Turn bold mode on ^[[1m *) PROCEDURE resetlowint; (*OK*) (* SGR2 Turn low intensity mode on ^[[2m *) PROCEDURE resetitalic; (*OK*) (* set italic mode ESC[3m *) PROCEDURE resetunderline; (*OK*) (* SGR4 Turn underline mode on ^[[4m *) PROCEDURE resetblink; (*OK*) (* SGR5 Turn blinking mode on ^[[5m *) PROCEDURE resetreverse; (*OK*) (* SGR7 Turn reverse video on ^[[7m *) PROCEDURE resetinvisible; (*OK*) (* SGR8 Turn invisible text mode on ^[[8m *) PROCEDURE resetstrikethrough; (*OK*) (* ESC[9m ESC[29m set strikethrough mode. *) PROCEDURE resetDoubleUnderline; (* ESC[24m. *) (* ESC Code Sequence Description ESC[H moves cursor to home position (0, 0) ESC[{line};{column}H ESC[{line};{column}f moves cursor to line #, column # ESC[#A moves cursor up # lines ESC[#B moves cursor down # lines ESC[#C moves cursor right # columns ESC[#D moves cursor left # columns ESC[#E moves cursor to beginning of next line, # lines down ESC[#F moves cursor to beginning of previous line, # lines up ESC[#G moves cursor to column # ESC[6n request cursor position (reports as ESC[#;#R) ESC M moves cursor one line up, scrolling if needed ESC 7 save cursor position (DEC) ESC 8 restores the cursor to the last saved position (DEC) ESC[s save cursor position (SCO) ESC[u restores the cursor to the last saved position (SCO) *) PROCEDURE requestCursorPosition(VAR x,y : CARDINAL); (* ESC[6n request cursor position (reports as ESC[#;#R) *) PROCEDURE cursorhome; (*OK*) (* Move cursor to upper left corner ^[[H *) PROCEDURE cursorhome1; (*OK*) (* Move cursor to upper left corner ^[[;H *) PROCEDURE cursorpos(x,y: CARDINAL); (*OK*) (* CUP Move cursor to screen location v,h ^[[;H *) PROCEDURE clearscreen; (* OK *) (* ED2 Clear entire screen ^[[2J *) (* Screen Modes Set Mode ESC Code Sequence Description ESC[={value}h Changes the screen width or type to the mode specified by value. ESC[=0h 40 x 25 monochrome (text) ESC[=1h 40 x 25 color (text) ESC[=2h 80 x 25 monochrome (text) ESC[=3h 80 x 25 color (text) ESC[=4h 320 x 200 4-color (graphics) ESC[=5h 320 x 200 monochrome (graphics) ESC[=6h 640 x 200 monochrome (graphics) ESC[=7h Enables line wrapping ESC[=13h 320 x 200 color (graphics) ESC[=14h 640 x 200 color (16-color graphics) ESC[=15h 640 x 350 monochrome (2-color graphics) ESC[=16h 640 x 350 color (16-color graphics) ESC[=17h 640 x 480 monochrome (2-color graphics) ESC[=18h 640 x 480 color (16-color graphics) ESC[=19h 320 x 200 color (256-color graphics) ESC[={value}l Resets the mode by using the same values that Set Mode uses, except for 7, which disables line wrapping. The last character in this escape sequence is a lowercase L. Common Private Modes *) PROCEDURE screenMode(mode : screenModes); PROCEDURE resetScreenMode(mode : screenModes); PROCEDURE lineWrapping; PROCEDURE resetLineWrapping; (* These are some examples of private modes, which are not defined by the specification, but are implemented in most terminals. ESC Code Sequence Description ESC[?25l make cursor invisible ESC[?25h make cursor visible ESC[?47l restore screen ESC[?47h save screen ESC[?1049h enables the alternative buffer ESC[?1049l disables the alternative buffer *) PROCEDURE makeCursorInvisible; PROCEDURE makeCursorVisible; PROCEDURE restoreScreen; PROCEDURE saveScreen; PROCEDURE enableAlternativeBuffer; PROCEDURE disableAlternativeBuffer; (* Color codes Most terminals support 8 and 16 colors, as well as 256 (8-bit) colors. These colors are set by the user, but have commonly defined meanings. 8-16 Colors Color Name Foreground Color Code Background Color Code Black 30 40 Red 31 41 Green 32 42 Yellow 33 43 Blue 34 44 Magenta 35 45 Cyan 36 46 White 37 47 Default 39 49 Reset 0 0 Note: the Reset color is the reset code that resets all colors and text effects, Use Default color to reset colors only. Most terminals, apart from the basic set of 8 colors, also support the "bright" or "bold" colors. These have their own set of codes, mirroring the normal colors, but with an additional ;1 in their codes: # Set style to bold, red foreground. \x1b[1;31mHello # Set style to dimmed white foreground with red background. \x1b[2;37;41mWorld Terminals that support the aixterm specification provides bright versions of the ISO colors, without the need to use the bold modifier: Color Name Foreground Color Code Background Color Code Bright Black 90 100 Bright Red 91 101 Bright Green 92 102 Bright Yellow 93 103 Bright Blue 94 104 Bright Magenta 95 105 Bright Cyan 96 106 Bright White 97 107 256 Colors *) PROCEDURE setAttribut ( attribut: Attribut; front, back : Colors); (* # # All codes below are for use in VT52 compatibility mode. # *) PROCEDURE VT52setansi; (*OK*) (* Enter/exit ANSI mode (VT52) ^[< *) PROCEDURE VT52altkeypad; (* Enter alternate keypad mode ^[= *) PROCEDURE VT52numkeypad; (* Exit alternate keypad mode ^[> *) PROCEDURE VT52setgr; (* NOT OK*) (* Use special graphics character set ^[F *) PROCEDURE VT52resetgr; (* NOT OK*) (* Use normal US/UK character set ^[G *) PROCEDURE VT52cursorup; (*OK*) (* Move cursor up one line ^[A *) PROCEDURE VT52cursordn; (*OK*) (* Move cursor down one line ^[B *) PROCEDURE VT52cursorrt; (*OK*) (* Move cursor right one char ^[C *) PROCEDURE VT52cursorlf; (*OK*) (* Move cursor left one char ^[D *) PROCEDURE VT52cursorhome; (*OK*) (* Move cursor to upper left corner ^[H *) PROCEDURE VT52cursorpos(x, y : CARDINAL); (* NOT OK*) (* Move cursor to v,h location ^[ *) PROCEDURE VT52revindex; (* Generate a reverse line-feed ^[I *) PROCEDURE VT52cleareol; (*OK*) (* Erase to end of current line ^[K *) PROCEDURE VT52cleareos; (*OK*) (* Erase to end of screen ^[J *) PROCEDURE VT52ident; (* Identify what the terminal is ^[Z *) PROCEDURE VT52identresp; (*Correct response to ident ^[/Z *) PROCEDURE CloseTerminal; (* PROCEDURE tcsetattr (fd: INTEGER; option: INTEGER; t: TERMIOS) : INTEGER ; *) PROCEDURE InitTerminal; (* PROCEDURE tcgetattr (fd: INTEGER; t: TERMIOS) : INTEGER ; *) END VT100.