home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / BIPL.ZIP / PROCS.ZIP / ANSI.ICN < prev    next >
Encoding:
Text File  |  1993-01-27  |  5.6 KB  |  213 lines

  1. ############################################################################ 
  2. #    File:     ansi.icn
  3. #    Subject:  Procedures for ANSI-based terminal control
  4. #    Author:   Ralph E. Griswold and Richard Goerwitz
  5. #
  6. #    Date:     February 8, 1992
  7. ########################################################################### 
  8. #
  9. #    Version:  1.4
  10. #
  11. ###########################################################################
  12. #     This package of procedures implements a subset of the ANSI terminal
  13. #  control sequences.  The names of the procedures are taken directly from
  14. #  the ANSI names.  If it is necessary to use these routines with non-ANSI
  15. #  devices, link in iolib.icn, and (optionally) iscreen.icn as well.  Use
  16. #  will be made of whatever routines are made available via either of these
  17. #  libraries.  Be careful of naming conflicts if you link in iscreen.icn.
  18. #  It contains procedures like "clear" and "boldface."
  19. #
  20. #     CUB(i)        Moves the cursor left i columns
  21. #     CUD(i)        Moves the cursor down i rows
  22. #     CUF(i)        Moves the cursor right i columns
  23. #     CUP(i,j)    Moves the cursor to row i, column j
  24. #     CUU(i)        Moves the cursor up i rows
  25. #     ED(i)        Erases screen: i = 0, cursor to end; i = 1,
  26. #               beginning to cursor; i = 2, all (default 2)
  27. #     EL(i)        Erases data in cursor row: i = 0, cursor to
  28. #               end; i = 1, beginning to cursor; i = 2, all
  29. #               (default 0)
  30. #     SGR(i)        Sets video attributes: 0 = off; 1 = bold; 4 =
  31. #               underscore; 5 = blink; 7 = reverse (default
  32. #               0)    
  33. #
  34. #     Note that not all so-called ANSI terminals support every ANSI
  35. #  screen control sequence - not even the limited subset included in
  36. #  this file.
  37. #
  38. #     If you plan on using these routines with non-ANSI magic-cookie
  39. #  terminals (e.g. a Wyse-50) then it is strongly recommended that you
  40. #  link in iolib or itlib *and* iscreen (not just iolib or itlib by
  41. #  itself).  The routines WILL WORK with most magic cookie terminals;
  42. #  they just don't always get all the modes displayed (because they
  43. #  are basically too busy erasing the cookies).
  44. #
  45. ############################################################################ 
  46. #
  47. # links: iolib or itlib, iscreen (all optional)
  48. #
  49. # see also: ansi.icn
  50. #
  51. ############################################################################ 
  52.  
  53. # For DOS, or any system using ANSI-conformant output devices, there
  54. # is no need to link any routines in.
  55.  
  56. # For UNIX systems, you may choose to link in itlib or iolib, and (if
  57. # desired) iscreen as well.  Some of these may be in the IPL.  You can
  58. # get any that aren't from Richard Goerwitz (goer@sophist.uchicago.edu).
  59.  
  60. # link iolib, iscreen
  61.  
  62. procedure _isANSI()
  63.     static isANSI
  64.     initial {
  65.     if find("MS-DOS",&features) then {
  66.         isANSI := 1
  67.     } else {
  68.         if proc(getname) then {
  69.         if find("ansi",map(getname())) | getname() == "li"
  70.         then isANSI := 1
  71.         else isANSI := &null
  72.         } else {
  73.         # We'll take a chance on the user knowing what he/she
  74.         # is doing.
  75.         isANSI := 1
  76.         # If you're not so confident, comment out the following
  77.         # line:
  78.         # stop("_isANSI:  you need to link itlib or iolib")
  79.         }
  80.     }
  81.     }
  82.     return \isANSI
  83. end
  84.  
  85. procedure CUD(i)
  86.     if _isANSI()
  87.     then writes("\^[[",i,"B")
  88.     else {
  89.     iputs(igoto(getval("DO"),i)) | {
  90.         every 1 to i do
  91.         iputs(getval("do")) | stop("CUD:  no do capability")
  92.     }
  93.     }
  94.     return
  95. end
  96.  
  97. procedure CUB(i)
  98.     if _isANSI()
  99.     then writes("\^[[",i,"D")
  100.     else {
  101.     iputs(igoto(getval("LE"),i)) | {
  102.         every 1 to i do
  103.         iputs(getval("le")) | stop("CUB:  no le capability")
  104.     }
  105.     }
  106.     return
  107. end
  108.  
  109. procedure CUF(i)
  110.     if _isANSI()
  111.     then writes("\^[[",i,"C")
  112.     else {
  113.     iputs(igoto(getval("RI"),i)) | {
  114.         every 1 to i do
  115.         iputs(getval("nd")) | stop("CUF:  no nd capability")
  116.     }
  117.     }
  118.     return
  119. end
  120.  
  121. procedure CUP(i,j)
  122.     if _isANSI()
  123.     then writes("\^[[",i,";",j,"H")
  124.     else iputs(igoto(getval("cm"), j, i)) | stop("CUP:  no cm capability")
  125.     return
  126. end
  127.  
  128. procedure CUU(i)
  129.     if _isANSI()
  130.     then writes("\^[[",i,"A")
  131.     else {
  132.     iputs(igoto(getval("UP"),i)) | {
  133.         every 1 to i do
  134.         iputs(getval("up")) | stop("CUU:  no up capability")
  135.     }
  136.     }
  137.     return
  138. end
  139.  
  140. procedure ED(i)
  141.     /i := 2
  142.     if _isANSI() then {
  143.     writes("\^[[",i,"J")
  144.     } else {
  145.     case i of {
  146.         0:  iputs(getval("cd")) | stop("ED:  no cd capability")
  147.         1:  stop("ED:  termcap doesn't specify capability")
  148.         2:  {
  149.         if proc(emphasize) then clear()
  150.         else iputs(getval("cl")) | stop("ED:  no cl capability")
  151.         }
  152.         default:  stop("ED:  unknown clear code, ",i)
  153.     }
  154.     }
  155.    return
  156. end
  157.  
  158. procedure EL(i)
  159.     /i := 0
  160.     if _isANSI() then {
  161.     if i = 0
  162.     then writes("\^[[K")
  163.     else writes("\^[[",i,"K")
  164.     } else {
  165.     case i of {
  166.         0:  iputs(getval("ce")) | stop("EL:  no ce capability")
  167.         1:  stop("EL:  termcap doesn't specify capability")
  168.         2:  stop("EL:  try using CUP to go to col 1, then EL(0)")
  169.         default:  stop("EL:  unknown line clear code, ",i)
  170.     }
  171.     }
  172.    return
  173. end
  174.  
  175. procedure SGR(i)
  176.  
  177.     static isISCR
  178.     initial {
  179.     if proc(emphasize)
  180.     then isISCR := 1
  181.     }
  182.  
  183.     /i := 0
  184.     if _isANSI() then {
  185.     writes("\^[[",i,"m")
  186.     } else {
  187.     case i of {
  188.         0: (\isISCR, normal()) | {
  189.         every iputs(getval("me"|"se"|"ue"))
  190.         }
  191.         1: (\isISCR, boldface()) | {
  192.         iputs(getval("md"|"so"|"us"))
  193.         }
  194.         4: (\isISCR, underline()) | {
  195.         iputs(getval("us"|"md"|"so"))
  196.         }
  197.         5: (\isISCR, blink()) | {
  198.         iputs(getval("mb"|"us"|"md"|"so"))
  199.         }
  200.         7: (\isISCR, emphasize()) | {
  201.         iputs(getval("so"|"md"|"us"))
  202.         }
  203.         default:  stop("SGR:  unknown mode, ",i)
  204.     }
  205.     }
  206.    return
  207. end
  208.