TermCfg.def 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. DEFINITION MODULE TermCfg ;
  2. (* Terminal escape sequences, loaded from a TEXT file. This is the whole
  3. point of the module: the shell never patches its own binary (TINST's
  4. approach); it reads a configuration at startup.
  5. FILE FORMAT - plain text, one KEY=value per line:
  6. ; a comment
  7. NAME=ANSI
  8. CLEAR=\e[2J\e[H
  9. HOME=\e[H
  10. GOTO=\e[%r;%cH
  11. NORMAL=\e[0m
  12. MARKED=\e[1;7m
  13. BEEP=^G
  14. `;' at the start of a line starts a comment. Blanks around the key and
  15. value are ignored. The key is case-insensitive.
  16. Values are DECODED, so the file stays readable and editable:
  17. \e or \E ESC (27) \r CR (13) \n LF (10)
  18. \t TAB (9) \\ a backslash
  19. ^X control-X (X uppercased, minus 64), e.g. ^G = BEL (7)
  20. GOTO may contain %r and %c; the shell substitutes the decimal row and
  21. column there (1-based, as TP3's GotoXY is). %% is a literal percent.
  22. A missing file, or a line with no '=', sets ok to FALSE and leaves the
  23. defaults (and anything read before the bad line) in place - never a
  24. silently half-written screen. *)
  25. CONST
  26. MaxSeq = 63 ;
  27. MaxName = 31 ;
  28. TYPE
  29. Cfg = RECORD
  30. name : ARRAY [0..MaxName] OF CHAR ;
  31. clear : ARRAY [0..MaxSeq] OF CHAR ;
  32. home : ARRAY [0..MaxSeq] OF CHAR ;
  33. moveTo : ARRAY [0..MaxSeq] OF CHAR ; (* GOTO: %r, %c *)
  34. normal : ARRAY [0..MaxSeq] OF CHAR ;
  35. marked : ARRAY [0..MaxSeq] OF CHAR ;
  36. beep : ARRAY [0..MaxSeq] OF CHAR ;
  37. END ;
  38. PROCEDURE ParseValue (src : ARRAY OF CHAR ; VAR dst : ARRAY OF CHAR) ;
  39. (* decode one value's escapes into dst: the same rules as a file's value, so
  40. a caller building a Cfg in memory spells it exactly as the file would. *)
  41. PROCEDURE Default (VAR c : Cfg) ;
  42. (* the ANSI set - what the shell used before there was a config file *)
  43. PROCEDURE Load (path : ARRAY OF CHAR ; VAR c : Cfg ; VAR ok : BOOLEAN) ;
  44. (* Default(c), then every KEY=value in path. ok is FALSE if the file could
  45. not be opened or a line is malformed. *)
  46. END TermCfg.