Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!midway!ellis.uchicago.edu!goer From: goer@ellis.uchicago.edu (Richard L. Goerwitz) Newsgroups: comp.lang.icon Subject: Re: ansi routines Message-ID: <1991Jun15.014043.20745@midway.uchicago.edu> Date: 15 Jun 91 01:40:43 GMT References: <9106142244.AA22433@relay2.UU.NET> Sender: news@midway.uchicago.edu (NewsMistress) Distribution: inet Organization: University of Chicago Lines: 243 In article <9106142244.AA22433@relay2.UU.NET> nowlin@isidev.UUCP writes: >We (ISI) would like to see the expanded ansi routines to compare with the >beta version of our Enhanced Character Interface (ECI). This is a >character based windowing interface implemented in Icon at the C level. We >demonstrated a prototype at the last ICEBOL conference. They are very minimal ANSI routines, and in fact are completely compatible with the ansi.icn file included in the IPL. I've been accumulating enough requests that I've decided to post the routines. They are appended below. >[Stuff on ECI - a great idea - deleted, as also some examples illustrating >high-level, generalized screen control.] > >We're interested in feedback on whether this functionality should be made a >standard part of our Icon or an add-on. The reason for making it an add-on >is because all this doesn't come for free. The size of iconx at least >doubles. Any and all comments are appreciated. Thanks. I'd vote that that you not include it as part of the standard package. First of all, is it OS-specific (only for systems with SysVr3 curses)? If so, then it definitely needs to be separated out. I hear of inter- faces being built for X, and perhaps for other visual environments, in addition to ECI. I guess I'd like to see them all built as add-ons. What would be really nice is if everyone kept in touch, and attempted to use a similar approach. -Richard ----------------------------- ansi2.icn ------------------------------ ############################################################################ # # Name: ansi2.icn # # Title: ANSI-based terminal control library # # Author: Ralph E. Griswold and Richard Goerwitz # # Version: 1.1 (pretty much untested) # ############################################################################ # # This package of procedures implements a subset of the ANSI terminal # control sequences. The names of the procedures are taken directly from # the ANSI names. If it is necessary to use these routines with non-ANSI # devices, link in iolib.icn, and (optionally) iscreen.icn as well. Use # will be made of whatever routines are made available via either of these # libraries. Be careful of naming conflicts if you link in iscreen.icn. # It contains procedures like "clear" and "boldface." # # CUB(i) Moves the cursor left i columns # CUD(i) Moves the cursor down i rows # CUF(i) Moves the cursor right i columns # CUP(i,j) Moves the cursor to row i, column j # CUU(i) Moves the cursor up i rows # ED(i) Erases screen: i = 0, cursor to end; i = 1, # beginning to cursor; i = 2, all (default 2) # EL(i) Erases data in cursor row: i = 0, cursor to # end; i = 1, beginning to cursor; i = 2, all # (default 0) # SGR(i) Sets video attributes: 0 = off; 1 = bold; 4 = # underscore; 5 = blink; 7 = reverse (default # 0) # # Note that not all so-called ANSI terminals support every ANSI # screen control sequence - not even the limited subset included in # this file. # # If you plan on using these routines with non-ANSI magic-cookie # terminals (e.g. a Wyse-50) then it is strongly recommended that you # link in iolib or itlib *and* iscreen (not just iolib or itlib by # itself). The routines WILL WORK with most magic cookie terminals; # they just don't always get all the modes displayed (because they # are basically too busy erasing the cookies). # ############################################################################ # # links: iolib or itlib, iscreen (all optional) # # see also: ansi.icn # ############################################################################ # For DOS, or any system using ANSI-conformant output devices, there # is no need to link any routines in. # For Unix systems, you may choose to link in itlib or iolib, and (if # desired) iscreen as well. Some of these may be in the IPL. You can # get any that aren't from Richard Goerwitz (goer@sophist.uchicago.edu). # link iolib, iscreen procedure _isANSI() static isANSI initial { if find("MS-DOS",&features) then { isANSI := 1 } else { if type(getname) == "procedure" then { if find("ansi",map(getname())) | getname() == "li" then isANSI := 1 else isANSI := &null } else { # We'll take a chance on the user knowing what he/she # is doing. isANSI := 1 # If you're not so confident, comment out the following # line: # stop("_isANSI: you need to link itlib or iolib") } } } return \isANSI end procedure CUD(i) if _isANSI() then writes("\^[[",i,"B") else { iputs(igoto(getval("DO"),i)) | { every 1 to i do iputs(getval("do")) | stop("CUD: no do capability") } } return end procedure CUB(i) if _isANSI() then writes("\^[[",i,"D") else { iputs(igoto(getval("LE"),i)) | { every 1 to i do iputs(getval("le")) | stop("CUB: no le capability") } } return end procedure CUF(i) if _isANSI() then writes("\^[[",i,"C") else { iputs(igoto(getval("RI"),i)) | { every 1 to i do iputs(getval("nd")) | stop("CUF: no nd capability") } } return end procedure CUP(i,j) if _isANSI() then writes("\^[[",i,";",j,"H") else iputs(igoto(getval("cm"), j, i)) | stop("CUP: no cm capability") return end procedure CUU(i) if _isANSI() then writes("\^[[",i,"A") else { iputs(igoto(getval("UP"),i)) | { every 1 to i do iputs(getval("up")) | stop("CUU: no up capability") } } return end procedure ED(i) /i := 2 if _isANSI() then { writes("\^[[",i,"J") } else { case i of { 0: iputs(getval("cd")) | stop("ED: no cd capability") 1: stop("ED: termcap doesn't specify capability") 2: { if type(emphasize) == "procedure" then clear() else iputs(getval("cl")) | stop("ED: no cl capability") } default: stop("ED: unknown clear code, ",i) } } return end procedure EL(i) /i := 0 if _isANSI() then { if i = 0 then writes("\^[[K") else writes("\^[[",i,"K") } else { case i of { 0: iputs(getval("ce")) | stop("EL: no ce capability") 1: stop("EL: termcap doesn't specify capability") 2: stop("EL: try using CUP to go to col 1, then EL(0)") default: stop("EL: unknown line clear code, ",i) } } return end procedure SGR(i) static isISCR initial { if type(emphasize) == "procedure" then isISCR := 1 } /i := 0 if _isANSI() then { writes("\^[[",i,"m") } else { case i of { 0: (\isISCR, normal()) | { every iputs(getval("me"|"so"|"ue")) } 1: (\isISCR, boldface()) | { iputs(getval("md"|"so"|"us")) } 4: (\isISCR, underline()) | { iputs(getval("us"|"md"|"so")) } 5: (\isISCR, blink()) | { iputs(getval("mb"|"us"|"me"|"so")) } 7: (\isISCR, emphasize()) | { iputs(getval("so"|"me"|"ue")) } default: stop("SGR: unknown mode, ",i) } } return end -- -Richard L. Goerwitz goer%sophist@uchicago.bitnet goer@sophist.uchicago.edu rutgers!oddjob!gide!sophist!goer