VT100.def 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. DEFINITION MODULE VT100;
  2. (*
  3. The POSIX function cfmakeraw() sets the canonical
  4. combination. Applications typically use tcgetattr()
  5. to save the current settings, call cfmakeraw()
  6. to switch to raw mode, and call tcsetattr() with
  7. the saved settings on exit to restore the terminal.
  8. *)
  9. TYPE
  10. screenModes = (M40x25BW,M40x25C,M80x25BW,M80x25C,M320x200C4,M320x200BW,M640x200BW,
  11. M320x200C256,M640x200C,M640x350BW,M640x350C,M640x480BW,M640x480C,M320x200C);
  12. Attribut = (boldAt,dimAt,italicAt,underlineAt,blinkingAt,inverseAt,hiddenAt,
  13. strikethroughAt,doubleunderlineAt);
  14. Colors = (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, Default,
  15. BrightBlack, BrightRed, BrightGreen, BrightYellow,
  16. BrightBlue, BrighMagenta, BrightCyan, BrightWhite);
  17. (*
  18. PROCEDURE setnl;
  19. (* LMN Set new line mode ^[[20h *)
  20. PROCEDURE setappl;
  21. (* DECCKM Set cursor key to application ^[[?1h *)
  22. PROCEDURE setansi;
  23. (* DECANM Set ANSI (versus VT52) none *)
  24. PROCEDURE setcol;
  25. (* DECCOLM Set number of columns to 132 ^[[?3h *)
  26. PROCEDURE setsmooth;
  27. (* DECSCLM Set smooth scrolling ^[[?4h *)
  28. PROCEDURE setrevscrn;
  29. (* DECSCNM Set reverse video on screen ^[[?5h *)
  30. PROCEDURE setorgrel;
  31. (* DECOM Set origin to relative ^[[?6h *)
  32. PROCEDURE setwrap;
  33. (* DECAWM Set auto-wrap mode ^[[?7h *)
  34. PROCEDURE setrep;
  35. (* DECARM Set auto-repeat mode ^[[?8h *)
  36. PROCEDURE setinter;
  37. (* DECINLM Set interlacing mode ^[[?9h *)
  38. PROCEDURE setlf;
  39. (* LMN Set line feed mode ^[[20l *)
  40. PROCEDURE setcursor;
  41. (* DECCKM Set cursor key to cursor ^[[?1l *)
  42. PROCEDURE setvt52;
  43. (* DECANM Set VT52 (versus ANSI) ^[[?2l *)
  44. PROCEDURE resetcol;
  45. (* DECCOLM Set number of columns to 80 ^[[?3l *)
  46. PROCEDURE setjump;
  47. (* DECSCLM Set jump scrolling ^[[?4l *)
  48. PROCEDURE setnormscrn;
  49. (* DECSCNM Set normal video on screen ^[[?5l *)
  50. PROCEDURE setorgabs;
  51. (* DECOM Set origin to absolute ^[[?6l *)
  52. PROCEDURE resetwrap;
  53. (* DECAWM Reset auto-wrap mode ^[[?7l *)
  54. PROCEDURE resetrep;
  55. (* DECARM Reset auto-repeat mode ^[[?8l *)
  56. PROCEDURE resetinter;
  57. (* DECINLM Reset interlacing mode ^[[?9l *)
  58. PROCEDURE altkeypad;
  59. (* DECKPAM Set alternate keypad mode ^[= *)
  60. PROCEDURE numkeypad;
  61. (* DECKPNM Set numeric keypad mode ^[> *)
  62. PROCEDURE setukg0;
  63. (* Set United Kingdom G0 character set ^[(A *)
  64. PROCEDURE setukg1;
  65. (* Set United Kingdom G1 character set ^[)A *)
  66. PROCEDURE setusg0;
  67. (* Set United States G0 character set ^[(B *)
  68. PROCEDURE setusg1;
  69. (* Set United States G1 character set ^[)B *)
  70. PROCEDURE setspecg0;
  71. (* Set G0 special chars. & line set ^[(0 *)
  72. PROCEDURE setspecg1;
  73. (* Set G1 special chars. & line set ^[)0 *)
  74. PROCEDURE setaltg0;
  75. (* Set G0 alternate character ROM ^[(1 *)
  76. PROCEDURE setaltg1;
  77. (* Set G1 alternate character ROM ^[)1 *)
  78. PROCEDURE setaltspecg0;
  79. (* Set G0 alt char ROM and spec. graphics ^[(2 *)
  80. PROCEDURE setaltspecg1;
  81. (* Set G1 alt char ROM and spec. graphics ^[)2 *)
  82. PROCEDURE setss2 ;
  83. (* SS2 Set single shift 2 ^[N *)
  84. PROCEDURE setss3;
  85. (* SS3 Set single shift 3 ^[O *)
  86. *)
  87. (*
  88. ESC Code Sequence Reset Sequence Description
  89. ESC[1;34;{...}m Set graphics modes for cell, separated by semicolon (;).
  90. ESC[1m ESC[22m set bold mode.
  91. ESC[2m ESC[22m set dim/faint mode.
  92. ESC[3m ESC[23m set italic mode.
  93. ESC[4m ESC[24m set underline mode.
  94. ESC[5m ESC[25m set blinking mode
  95. ESC[7m ESC[27m set inverse/reverse mode
  96. ESC[8m ESC[28m set hidden/invisible mode
  97. ESC[9m ESC[29m set strikethrough mode.
  98. ESC[21m ESC[24m set double underline
  99. *)
  100. PROCEDURE modesoff; (*OK*)
  101. (* SGR0 Turn off character attributes ^[[m *)
  102. PROCEDURE modesoff1; (*OK*)
  103. (* SGR0 Turn off character attributes ^[[0m *)
  104. PROCEDURE bold; (*OK*)
  105. (* SGR1 Turn bold mode on ^[[1m *)
  106. PROCEDURE lowint; (*OK*)
  107. (* SGR2 Turn low intensity mode on ^[[2m *)
  108. PROCEDURE italic; (*OK*)
  109. (* set italic mode ESC[3m *)
  110. PROCEDURE underline; (*OK*)
  111. (* SGR4 Turn underline mode on ^[[4m *)
  112. PROCEDURE blink; (*OK*)
  113. (* SGR5 Turn blinking mode on ^[[5m *)
  114. PROCEDURE reverse; (*OK*)
  115. (* SGR7 Turn reverse video on ^[[7m *)
  116. PROCEDURE invisible; (*OK*)
  117. (* SGR8 Turn invisible text mode on ^[[8m *)
  118. PROCEDURE strikethrough; (*OK*)
  119. (* ESC[9m ESC[29m set strikethrough mode. *)
  120. PROCEDURE doubleUnderline;
  121. (* ESC[21m *)
  122. PROCEDURE resetbold; (*OK*)
  123. (* SGR1 Turn bold mode on ^[[1m *)
  124. PROCEDURE resetlowint; (*OK*)
  125. (* SGR2 Turn low intensity mode on ^[[2m *)
  126. PROCEDURE resetitalic; (*OK*)
  127. (* set italic mode ESC[3m *)
  128. PROCEDURE resetunderline; (*OK*)
  129. (* SGR4 Turn underline mode on ^[[4m *)
  130. PROCEDURE resetblink; (*OK*)
  131. (* SGR5 Turn blinking mode on ^[[5m *)
  132. PROCEDURE resetreverse; (*OK*)
  133. (* SGR7 Turn reverse video on ^[[7m *)
  134. PROCEDURE resetinvisible; (*OK*)
  135. (* SGR8 Turn invisible text mode on ^[[8m *)
  136. PROCEDURE resetstrikethrough; (*OK*)
  137. (* ESC[9m ESC[29m set strikethrough mode. *)
  138. PROCEDURE resetDoubleUnderline;
  139. (* ESC[24m. *)
  140. (*
  141. PROCEDURE setwin;
  142. (* DECSTBM Set top and bottom line#s of a window ^[[<v>;<v>r *)
  143. *)
  144. (*
  145. ESC Code Sequence Description
  146. ESC[H moves cursor to home position (0, 0)
  147. ESC[{line};{column}H
  148. ESC[{line};{column}f moves cursor to line #, column #
  149. ESC[#A moves cursor up # lines
  150. ESC[#B moves cursor down # lines
  151. ESC[#C moves cursor right # columns
  152. ESC[#D moves cursor left # columns
  153. ESC[#E moves cursor to beginning of next line, # lines down
  154. ESC[#F moves cursor to beginning of previous line, # lines up
  155. ESC[#G moves cursor to column #
  156. ESC[6n request cursor position (reports as ESC[#;#R)
  157. ESC M moves cursor one line up, scrolling if needed
  158. ESC 7 save cursor position (DEC)
  159. ESC 8 restores the cursor to the last saved position (DEC)
  160. ESC[s save cursor position (SCO)
  161. ESC[u restores the cursor to the last saved position (SCO)
  162. *)
  163. PROCEDURE cursorup(n : CARDINAL); (*OK*)
  164. (* CUU Move cursor up n lines ^[[<n>A *)
  165. PROCEDURE cursordn(n : CARDINAL); (*OK*)
  166. (* CUD Move cursor down n lines ^[[<n>B *)
  167. PROCEDURE cursorrt(n : CARDINAL); (*OK*)
  168. (* CUF Move cursor right n lines ^[[<n>C *)
  169. PROCEDURE cursor1lf(n : CARDINAL); (*OK*)
  170. (* CUB Move cursor left n lines ^[[<n>D *)
  171. PROCEDURE cursorbnl(n : CARDINAL);
  172. (* ESC[#E moves cursor to beginning of next line, # lines down *)
  173. PROCEDURE cursorblpl(n : CARDINAL);
  174. (* ESC[#F moves cursor to beginning of previous line, # lines up *)
  175. PROCEDURE cursottocol(n : CARDINAL);
  176. (* ESC[#G moves cursor to column # *)
  177. PROCEDURE requestCursorPosition(VAR x,y : CARDINAL);
  178. (* ESC[6n request cursor position (reports as ESC[#;#R) *)
  179. PROCEDURE cursorhome; (*OK*)
  180. (* Move cursor to upper left corner ^[[H *)
  181. PROCEDURE cursorhome1; (*OK*)
  182. (* Move cursor to upper left corner ^[[;H *)
  183. PROCEDURE cursorpos(x,y: CARDINAL); (*OK*)
  184. (* CUP Move cursor to screen location v,h ^[[<v>;<h>H *)
  185. (*
  186. PROCEDURE hvhome;
  187. (* Move cursor to upper left corner ^[[f *)
  188. PROCEDURE hvhome;
  189. (* Move cursor to upper left corner ^[[;f *)
  190. PROCEDURE hvpos(v,h);
  191. (* CUP Move cursor to screen location v,h ^[[<v>;<h>f *)
  192. PROCEDURE index;
  193. (* IND Move/scroll window up one line ^[D *)
  194. PROCEDURE revindex;
  195. (* RI Move/scroll window down one line ^[M *)
  196. PROCEDURE nextline;
  197. (* NEL Move to next line ^[E *)
  198. PROCEDURE savecursor;
  199. (* DECSC Save cursor position and attributes ^[7 *)
  200. PROCEDURE restorecursor;
  201. (* DECSC Restore cursor position and attributes ^[8 *)
  202. PROCEDURE tabset;
  203. (* HTS Set a tab at the current column ^[H *)
  204. PROCEDURE tabclr;
  205. (* TBC Clear a tab at the current column ^[[g *)
  206. PROCEDURE tabclr;
  207. (* TBC Clear a tab at the current column ^[[0g *)
  208. PROCEDURE tabclrall;
  209. (* TBC Clear all tabs ^[[3g *)
  210. PROCEDURE dhtop;
  211. (* DECDHL Double-height letters, top half ^[#3 *)
  212. PROCEDURE dhbot;
  213. (* DECDHL Double-height letters, bottom half ^[#4 *)
  214. PROCEDURE swsh;
  215. (* DECSWL Single width, single height letters ^[#5 *)
  216. PROCEDURE dwsh;
  217. (* DECDWL Double width, single height letters ^[#6 *)
  218. PROCEDURE cleareol;
  219. (* EL0 Clear line from cursor right ^[[K *)
  220. PROCEDURE cleareol;
  221. (* EL0 Clear line from cursor right ^[[0K *)
  222. PROCEDURE clearbol;
  223. (* EL1 Clear line from cursor left ^[[1K *)
  224. PROCEDURE clearline;
  225. (* EL2 Clear entire line ^[[2K *)
  226. PROCEDURE cleareos;
  227. (* ED0 Clear screen from cursor down ^[[J *)
  228. PROCEDURE cleareos;
  229. (* ED0 Clear screen from cursor down ^[[0J *)
  230. PROCEDURE clearbos;
  231. (* ED1 Clear screen from cursor up ^[[1J *)
  232. *)
  233. PROCEDURE clearscreen; (* OK *)
  234. (* ED2 Clear entire screen ^[[2J *)
  235. (*
  236. PROCEDURE devstat;
  237. (* DSR Device status report ^[5n *)
  238. PROCEDURE termok;
  239. (* DSR Response: terminal is OK ^[0n *)
  240. PROCEDURE termnok;
  241. (* DSR Response: terminal is not OK ^[3n *)
  242. PROCEDURE getcursor;
  243. (* DSR Get cursor position ^[6n *)
  244. PROCEDURE cursorpos;
  245. (* CPR Response: cursor is at v,h ^[<v>;<h>R *)
  246. PROCEDURE ident;
  247. (* DA Identify what terminal type ^[[c *)
  248. PROCEDURE ident;
  249. (* DA Identify what terminal type (another) ^[[0c *)
  250. PROCEDURE gettype;
  251. (* DA Response: terminal type code n ^[[?1;<n>0c *)
  252. PROCEDURE reset;
  253. (* RIS Reset terminal to initial state ^[c *)
  254. PROCEDURE align;
  255. (* DECALN Screen alignment display ^[#8 *)
  256. PROCEDURE testpu;
  257. (* DECTST Confidence power up test ^[[2;1y *)
  258. PROCEDURE testlb;
  259. (* DECTST Confidence loopback test ^[[2;2y *)
  260. PROCEDURE testpurep;
  261. (* DECTST Repeat power up test ^[[2;9y *)
  262. PROCEDURE testlbrep;
  263. (* DECTST Repeat loopback test ^[[2;10y *)
  264. PROCEDURE ledsoff;
  265. (* DECLL0 Turn off all four leds ^[[0q *)
  266. PROCEDURE led1;
  267. (* DECLL1 Turn on LED #1 ^[[1q *)
  268. PROCEDURE led2;
  269. (* DECLL2 Turn on LED #2 ^[[2q *)
  270. PROCEDURE led3;
  271. (* DECLL3 Turn on LED #3 ^[[3q *)
  272. PROCEDURE led4;
  273. (* DECLL4 Turn on LED #4 ^[[4q *)
  274. *)
  275. (*
  276. Screen Modes
  277. Set Mode
  278. ESC Code Sequence Description
  279. ESC[={value}h Changes the screen width or type to the mode specified by value.
  280. ESC[=0h 40 x 25 monochrome (text)
  281. ESC[=1h 40 x 25 color (text)
  282. ESC[=2h 80 x 25 monochrome (text)
  283. ESC[=3h 80 x 25 color (text)
  284. ESC[=4h 320 x 200 4-color (graphics)
  285. ESC[=5h 320 x 200 monochrome (graphics)
  286. ESC[=6h 640 x 200 monochrome (graphics)
  287. ESC[=7h Enables line wrapping
  288. ESC[=13h 320 x 200 color (graphics)
  289. ESC[=14h 640 x 200 color (16-color graphics)
  290. ESC[=15h 640 x 350 monochrome (2-color graphics)
  291. ESC[=16h 640 x 350 color (16-color graphics)
  292. ESC[=17h 640 x 480 monochrome (2-color graphics)
  293. ESC[=18h 640 x 480 color (16-color graphics)
  294. ESC[=19h 320 x 200 color (256-color graphics)
  295. 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.
  296. Common Private Modes
  297. *)
  298. PROCEDURE screenMode(mode : screenModes);
  299. PROCEDURE resetScreenMode(mode : screenModes);
  300. PROCEDURE lineWrapping;
  301. PROCEDURE resetLineWrapping;
  302. (*
  303. These are some examples of private modes, which are not defined by the specification, but are implemented in most terminals.
  304. ESC Code Sequence Description
  305. ESC[?25l make cursor invisible
  306. ESC[?25h make cursor visible
  307. ESC[?47l restore screen
  308. ESC[?47h save screen
  309. ESC[?1049h enables the alternative buffer
  310. ESC[?1049l disables the alternative buffer
  311. *)
  312. PROCEDURE makeCursorInvisible;
  313. PROCEDURE makeCursorVisible;
  314. PROCEDURE restoreScreen;
  315. PROCEDURE saveScreen;
  316. PROCEDURE enableAlternativeBuffer;
  317. PROCEDURE disableAlternativeBuffer;
  318. (*
  319. Color codes
  320. 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.
  321. 8-16 Colors
  322. Color Name Foreground Color Code Background Color Code
  323. Black 30 40
  324. Red 31 41
  325. Green 32 42
  326. Yellow 33 43
  327. Blue 34 44
  328. Magenta 35 45
  329. Cyan 36 46
  330. White 37 47
  331. Default 39 49
  332. Reset 0 0
  333. Note: the Reset color is the reset code that resets all colors and text effects, Use Default color to reset colors only.
  334. 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:
  335. # Set style to bold, red foreground.
  336. \x1b[1;31mHello
  337. # Set style to dimmed white foreground with red background.
  338. \x1b[2;37;41mWorld
  339. Terminals that support the aixterm specification provides bright versions of the ISO colors, without the need to use the bold modifier:
  340. Color Name Foreground Color Code Background Color Code
  341. Bright Black 90 100
  342. Bright Red 91 101
  343. Bright Green 92 102
  344. Bright Yellow 93 103
  345. Bright Blue 94 104
  346. Bright Magenta 95 105
  347. Bright Cyan 96 106
  348. Bright White 97 107
  349. 256 Colors
  350. *)
  351. PROCEDURE setAttribut ( attribut: Attribut; front, back : Colors);
  352. (*
  353. #
  354. # All codes below are for use in VT52 compatibility mode.
  355. #
  356. *)
  357. PROCEDURE VT52setansi; (*OK*)
  358. (* Enter/exit ANSI mode (VT52) ^[< *)
  359. PROCEDURE VT52altkeypad;
  360. (* Enter alternate keypad mode ^[= *)
  361. PROCEDURE VT52numkeypad;
  362. (* Exit alternate keypad mode ^[> *)
  363. PROCEDURE VT52setgr; (* NOT OK*)
  364. (* Use special graphics character set ^[F *)
  365. PROCEDURE VT52resetgr; (* NOT OK*)
  366. (* Use normal US/UK character set ^[G *)
  367. PROCEDURE VT52cursorup; (*OK*)
  368. (* Move cursor up one line ^[A *)
  369. PROCEDURE VT52cursordn; (*OK*)
  370. (* Move cursor down one line ^[B *)
  371. PROCEDURE VT52cursorrt; (*OK*)
  372. (* Move cursor right one char ^[C *)
  373. PROCEDURE VT52cursorlf; (*OK*)
  374. (* Move cursor left one char ^[D *)
  375. PROCEDURE VT52cursorhome; (*OK*)
  376. (* Move cursor to upper left corner ^[H *)
  377. PROCEDURE VT52cursorpos(x, y : CARDINAL); (* NOT OK*)
  378. (* Move cursor to v,h location ^[<v><h> *)
  379. PROCEDURE VT52revindex;
  380. (* Generate a reverse line-feed ^[I *)
  381. PROCEDURE VT52cleareol; (*OK*)
  382. (* Erase to end of current line ^[K *)
  383. PROCEDURE VT52cleareos; (*OK*)
  384. (* Erase to end of screen ^[J *)
  385. PROCEDURE VT52ident;
  386. (* Identify what the terminal is ^[Z *)
  387. PROCEDURE VT52identresp;
  388. (*Correct response to ident ^[/Z *)
  389. PROCEDURE CloseTerminal;
  390. (* PROCEDURE tcsetattr (fd: INTEGER; option: INTEGER; t: TERMIOS) : INTEGER ; *)
  391. PROCEDURE InitTerminal;
  392. (* PROCEDURE tcgetattr (fd: INTEGER; t: TERMIOS) : INTEGER ; *)
  393. END VT100.