source: cprs/branches/tmg-cprs/m_files/TMGTERM.m@ 1085

Last change on this file since 1085 was 796, checked in by Kevin Toppenberg, 14 years ago

Initial upload

File size: 15.3 KB
Line 
1TMGTERM ;TMG/kst/Terminal interface (ANSI sequences) ;03/25/06
2 ;;1.0;TMG-LIB;**1**;09/01/05
3
4 ;"Terminal interface
5 ;"ANSI Standard (X3.64) Control Sequences for Video Terminals and Peripherals
6 ;" in alphabetic order by mnemonic
7
8 ;"Terminal interface
9 ;"ANSI Standard (X3.64) Control Sequences for Video Terminals and Peripherals
10 ;" in alphabetic order by mnemonic
11
12 ;"CBT(Pn) ;CBT Cursor Backward Tab Esc [ Pn Z
13 ;"CCH ;Cancel Previous Character Esc T
14 ;"CHA(Pn) ;Cursor Horzntal Absolute Esc [ Pn G
15 ;"CHT(Pn) ;Cursor Horizontal Tab Esc [ Pn I
16 ;"CNL(Pn) ;Cursor Next Line Esc [ Pn E
17 ;"CPL(Pn) ;Cursor Preceding Line Esc [ Pn F
18 ;"CPR(Pn,P2) ;Cursor Position Report Esc [ Pn ; Pn R VT100
19 ;"CTC(Pn) ;Cursor Tab Control Esc [ Ps W
20 ;"CUB(Pn) ;Cursor Backward Esc [ Pn D VT100
21 ;"CUD(Pn) ;Cursor Down Esc [ Pn B VT100
22 ;"CUF(Pn) ;Cursor Forward Esc [ Pn C VT100
23 ;"CUP(X,Y) ;Cursor Position Esc [ Pn ; Pn H VT100
24 ;"HOME ;Cursor Home Esc [ H ('home' is top left)
25 ;"CUU(Pn) ;Cursor Up Esc [ Pn A VT100
26 ;"CVT(Pn) ;Cursor Vertical Tab Esc [ Pn Y
27 ;"DCH(Pn) ;Delete Character Esc [ Pn P
28 ;"DL(Pn) ;Delete Line Esc [ Pn M
29 ;"EA(Pn) ;Erase in Area Esc [ Ps O
30 ;"ECH(Pn) ;Erase Character Esc [ Pn X
31 ;"ED(Pn) ;Erase in Display Esc [ Ps J VT100
32 ;"EF(Pn) ;Erase in Field Esc [ Ps N
33 ;"EL(Pn) ;Erase in Line Esc [ Ps K VT100
34 ;"EPA ;End of Protected Area Esc W
35 ;"ESA ;End of Selected Area Esc G
36 ;"FNT(Pn,P2) ;Font Selection Esc [ Pn ; Pn Space D
37 ;"GSM(Pn,P2) ;Graphic Size Modify Esc [ Pn ; Pn Space B
38 ;"GSS(Pn) ;Graphic Size Selection Esc [ Pn Space C
39 ;"HPA(Pn) ;Horz Position Absolute Esc [ Pn `
40 ;"HPR(Pn) ;Horz Position Relative Esc [ Pn a
41 ;"HTJ ;Horz Tab w/Justification Esc I
42 ;"HTS ;Horizontal Tab Set Esc H VT100
43 ;"HVP(Pn,P2) ;Horz & Vertical Position Esc [ Pn ; Pn f VT100
44 ;"ICH(Pn) ;Insert Character Esc [ Pn @
45 ;"IL(Pn) ;Insert Line Esc [ Pn L
46 ;"IND ;Index Esc D VT100
47 ;"NEL ;Next Line Esc E VT100
48 ;"NP(Pn) ;Next Page Esc [ Pn U
49 ;"PP(Pn) ;Preceding Page Esc [ Pn V
50 ;"IS ;Reset to Initial State Esc c
51 ;"RM(Pn) ;Reset Mode Esc [ Ps l VT100
52 ;"SD(Pn) ;Scroll Down Esc [ Pn T
53 ;"SL(Pn) ;Scroll Left Esc [ Pn Space @
54 ;"SM(Pn) ;Select Mode Esc [ Ps h VT100
55 ;"SPA ;Start of Protected Area Esc V
56 ;"SPI(Pn,P2) ;Spacing Increment Esc [ Pn ; Pn Space G
57 ;"SR(Pn) ;Scroll Right Esc [ Pn Space A
58 ;"SA ;Start of Selected Area Esc F
59 ;"ST ;String Terminator Esc \
60 ;"SU(Pn) ;Scroll Up Esc [ Pn S
61 ;"TBC(Pn) ;Tab Clear Esc [ Ps g VT100
62 ;"VPA(Pn) ;Vert Position Absolute Esc [ Pn d
63 ;"VPR(Pn) ;Vert Position Relative Esc [ Pn e
64 ;"VCULOAD ;Unsave Cursor ESC [ u
65 ;"VCUSAV2 ;Save Cursor & Attrs ESC 7
66 ;"VCULOAD2 ;Restore Cursor & Attrs ESC 8
67
68 ;"VT100 specific calls
69 ;"--------------------
70 ;"VCEL ;Erase from cursor to end of line Esc [ 0 K or Esc [ K
71 ;"VCBL ;Erase from beginning of line to cursor Esc [ 1 K
72 ;"VEL ;Erase line containing cursor Esc [ 2 K
73 ;"VCES ;Erase from cursor to end of screen Esc [ 0 J or Esc [ J
74 ;"VCBS ;Erase from beginning of screen to cursor Esc [ 1 J
75 ;"VCS ;Erase entire screen Esc [ 2 J
76 ;"VCUSAV ;Save Cursor ESC [ s
77 ;"VTATRIB(n) ;Set Text attributes <ESC>[{attr1};...;{attrn}m
78 ;"VFGCOLOR(n);Set Text Foreground Color <ESC>[{attr1};...;{attrn}m
79 ;"VBGCOLOR(n);Set Text Background Color <ESC>[{attr1};...;{attrn}m
80 ;"VCOLORS(FG,BG) ;Set Text Colors <ESC>[{attr1};...;{attrn}m
81 ;"SetGlobals
82 ;"KillGlobals
83 ;"DemoColors
84 ;"DemoClr2
85
86
87 ;"=====================================================
88
89
90EscN(Num,N2,Cmd)
91 new tempX,tempY
92 set tempX=$X
93 set tempY=$Y
94 set $X=1 ;"ensure escape chars don't cause a wrap.
95 write $char(27,91)_Num
96 if $data(N2) write ";"_N2
97 if $data(Cmd) write Cmd
98 ;"reset $X,$Y so that escape characters aren't counted for line wrapping
99 set $X=tempX
100 set $Y=tempY
101 quit
102
103CBT(Pn) ;"CBT Cursor Backward Tab Esc [ Pn Z
104 do EscN(.Pn,,"Z")
105 quit
106
107CCH ;"Cancel Previous Character Esc T
108 write $char(27)_"T"
109
110CHA(Pn) ;"Cursor Horzntal Absolute Esc [ Pn G
111 do EscN(.Pn,,"G")
112 set $X=Pn
113 quit
114
115CHT(Pn) ;"Cursor Horizontal Tab Esc [ Pn I
116 do EscN(.Pn,,"I") quit
117
118CNL(Pn) ;"Cursor Next Line Esc [ Pn E
119 do EscN(.Pn,,"E")
120 set $Y=$Y+1
121 quit
122
123CPL(Pn) ;"Cursor Preceding Line Esc [ Pn F
124 do EscN(.Pn,,"F")
125 if $Y>0 set $Y=$Y-1
126 quit
127
128CPR(Pn,P2) ;"Cursor Position Report Esc [ Pn ; Pn R VT100
129 do EscN(.Pn,.P2,"R") quit
130
131CTC(Pn) ;"Cursor Tab Control Esc [ Ps W
132 do EscN(.Pn,,"W") quit
133
134CUB(Pn) ;"Cursor Backward Esc [ Pn D VT100
135 do EscN(.Pn,,"D")
136 set $X=$X-1
137 quit
138
139CUD(Pn) ;"Cursor Down Esc [ Pn B VT100
140 do EscN(.Pn,,"B")
141 set $Y=$Y+1
142 quit
143
144CUF(Pn) ;"Cursor Forward Esc [ Pn C VT100
145 do EscN(.Pn,,"C")
146 set $X=$X+1
147 quit
148
149CUP(X,Y) ;"Cursor Position Esc [ Pn ; Pn H VT100
150 do EscN(.Y,.X,"H")
151 set $X=X
152 set $Y=Y
153 quit
154
155HOME ;"Cursor Home Esc [ H ('home' is top left)
156 set $X=1 ;"ensure characters below don't cause a wrap.
157 w $char(27,91)_"H"
158 set $X=1 ;"now set $X to home value.
159 set $Y=1
160 quit
161
162CUU(Pn) ;"Cursor Up Esc [ Pn A VT100
163 do EscN(.Pn,,"A")
164 set $Y=$Y-1
165 quit
166
167CVT(Pn) ;"Cursor Vertical Tab Esc [ Pn Y
168 do EscN(.Pn,,"Y") quit
169
170DCH(Pn) ;"Delete Character Esc [ Pn P
171 do EscN(.Pn,,"P") quit
172
173DL(Pn) ;"Delete Line Esc [ Pn M
174 do EscN(.Pn,,"M") quit
175
176EA(Pn) ;"Erase in Area Esc [ Ps O
177 do EscN(.Pn,,"O") quit
178
179ECH(Pn) ;"Erase Character Esc [ Pn X
180 do EscN(.Pn,,"X") quit
181
182ED(Pn) ;"Erase in Display Esc [ Ps J VT100
183 do EscN(.Pn,,"J") quit
184
185EF(Pn) ;"Erase in Field Esc [ Ps N
186 do EscN(.Pn,,"N") quit
187
188EL(Pn) ;"Erase in Line Esc [ Ps K VT100
189 do EscN(.Pn,,"K") quit
190
191EPA ;"End of Protected Area Esc W
192 w $char(27)_"W" quit
193
194ESA ;"End of Selected Area Esc G
195 w $char(27)_"G" quit
196
197FNT(Pn,P2) ;"Font Selection Esc [ Pn ; Pn Space D
198 do EscN(.Pn,P2,"D") quit
199
200GSM(Pn,P2) ;"Graphic Size Modify Esc [ Pn ; Pn Space B
201 do EscN(.Pn,P2,"B") quit
202
203GSS(Pn) ;"Graphic Size Selection Esc [ Pn Space C
204 do EscN(.Pn,,"C") quit
205
206HPA(Pn) ;"Horz Position Absolute Esc [ Pn `
207 do EscN(.Pn,,"`") quit
208
209HPR(Pn) ;"Horz Position Relative Esc [ Pn a
210 do EscN(.Pn,,"a") quit
211
212HTJ ;"Horz Tab w/Justification Esc I
213 w $char(27)_"I" quit
214
215HTS ;"Horizontal Tab Set Esc H VT100
216 w $char(27)_"H" quit
217
218HVP(Pn,P2) ;"Horz & Vertical Position Esc [ Pn ; Pn f VT100
219 do EscN(.Pn,P2,"A") quit
220
221ICH(Pn) ;"Insert Character Esc [ Pn @
222 do EscN(.Pn,,"@") quit
223
224IL(Pn) ;"Insert Line Esc [ Pn L
225 do EscN(.Pn,,"L") quit
226
227IND ;"Index Esc D VT100
228 w $char(27)_"D" quit
229
230NEL ;"Next Line Esc E VT100
231 w $char(27)_"E" quit
232
233NP(Pn) ;"Next Page Esc [ Pn U
234 do EscN(.Pn,,"U") quit
235
236PP(Pn) ;"Preceding Page Esc [ Pn V
237 do EscN(.Pn,,"V") quit
238
239IS ;"Reset to Initial State Esc c
240 w $char(27)_"c" quit
241
242RM(Pn) ;"Reset Mode Esc [ Ps l VT100
243 do EscN(.Pn,,"l") quit
244
245SD(Pn) ;"Scroll Down Esc [ Pn T
246 do EscN(.Pn,,"T") quit
247
248SL(Pn) ;"Scroll Left Esc [ Pn Space @
249 do EscN(.Pn,," @") quit
250
251SM(Pn) ;"Select Mode Esc [ Ps h VT100
252 do EscN(.Pn,,"h") quit
253
254SPA ;"Start of Protected Area Esc V
255 w $char(27)_"V" quit
256
257SPI(Pn,P2) ;"Spacing Increment Esc [ Pn ; Pn Space G
258 do EscN(.Pn,P2," G") quit
259
260SR(Pn) ;"Scroll Right Esc [ Pn Space A
261 do EscN(.Pn,," A") quit
262
263SA ;"Start of Selected Area Esc F
264 w $char(27)_"F" quit
265
266ST ;"String Terminator Esc \
267 w $char(27)_"\" quit
268
269SU(Pn) ;"Scroll Up Esc [ Pn S
270 do EscN(.Pn,,"S") quit
271
272TBC(Pn) ;"Tab Clear Esc [ Ps g VT100
273 do EscN(.Pn,,"g") quit
274
275VPA(Pn) ;"Vert Position Absolute Esc [ Pn d
276 do EscN(.Pn,,"d") quit
277
278VPR(Pn) ;"Vert Position Relative Esc [ Pn e
279 do EscN(.Pn,,"e") quit
280
281
282VCULOAD ;"Unsave Cursor ESC [ u
283 w $char(27,91)_"u" quit
284
285VCUSAV2 ;"Save Cursor & Attrs ESC 7
286 w $char(27)_"7" quit
287
288VCULOAD2 ;"Restore Cursor & Attrs ESC 8
289 w $char(27)_"8" quit
290
291
292 ;"--------------------------------------------------------------
293 ;"VT100 specific calls
294 ;"Terminal interface
295
296VCEL ;"Erase from cursor to end of line Esc [ 0 K or Esc [ K
297 do EscN("0",,"K") quit
298
299VCBL ;"Erase from beginning of line to cursor Esc [ 1 K
300 do EscN("1",,"K") quit
301
302VEL ;"Erase line containing cursor Esc [ 2 K
303 do EscN("2",,"K") quit
304
305VCES ;"Erase from cursor to end of screen Esc [ 0 J or Esc [ J
306 do EscN("0",,"J") quit
307
308VCBS ;"Erase from beginning of screen to cursor Esc [ 1 J
309 do EscN("1",,"J") quit
310
311VCS ;"Erase entire screen Esc [ 2 J
312 do EscN("2",,"J") quit
313
314VCUSAV ;"Save Cursor ESC [ s
315 w $char(27,91)_"s" quit
316
317 ;"VCULOAD ;"Unsave Cursor ESC [ u
318 ;" w $char(27,91)_"u" quit
319
320 ;"VCUSAV2 ;"Save Cursor & Attrs ESC 7
321 ;" w $char(27)_"7" quit
322
323 ;"VCULOAD2 ;"Restore Cursor & Attrs ESC 8
324 ;" w $char(27)_"8" quit
325
326VTATRIB(n) ;"Set Text attributes <ESC>[{attr1};...;{attrn}m
327 ;"0-Reset all attributes
328 ;"1-Bright
329 ;"2-Dim
330 ;"4-Underscore
331 ;"5-Blink
332 ;"7-Reverse
333 ;"8-Hidden
334 do EscN(n,,"m") quit
335
336VFGCOLOR(n) ;"Set Text Foreground Color <ESC>[{attr1};...;{attrn}m
337 ;"See note about colors in VCOLORS
338 do VTATRIB(0)
339 if n>7 do
340 . do VTATRIB(1)
341 . set n=n-7
342 set n=n+30
343 do EscN(n,,"m") quit
344
345VBGCOLOR(n) ;"Set Text Background Color <ESC>[{attr1};...;{attrn}m
346 ;"See note about colors in VCOLORS
347 do VTATRIB(0)
348 if n>7 do
349 . do VTATRIB(1)
350 . set n=n-7
351 set n=n+40
352 do EscN(n,,"m") quit
353
354VCOLORS(FG,BG) ;Set Text Colors <ESC>[{attr1};...;{attrn}m
355 ;"Note: 5/29/06 I don't know if the color numbers are working
356 ;" correctly. The best way to determine what the color should
357 ;" be is to run DemoColor and pick the numbers wanted for desired colors
358 do VTATRIB(0)
359 if FG>7 do
360 . do VTATRIB(1)
361 . set FG=FG-7
362 if BG>7 do
363 . do VTATRIB(1)
364 . set BG=BG-7
365
366 set FG=FG+30
367 set BG=BG+40
368 do EscN(FG,BG,"m") quit
369 quit
370
371SetGlobals
372 set TMGcBlack=0
373 set TMGcRed=1
374 set TMGcGreen=2
375 set TMGcYellow=3
376 set TMGcBlue=4
377 set TMGcMagenta=5
378 set TMGcCyan=6
379 set TMGcGrey=7
380
381 set TMGcBRed=8
382 set TMGcBGreen=9
383 set TMGcBYellow=10
384 set TMGcBBlue=11
385 set TMGcBMagenta=12
386 set TMGcBCyan=13
387 set TMGcBGrey=14,TMGcFGBWhite=14
388 set TMGcWhite=15
389
390 quit
391
392KillGlobals
393 kill TMGcBlack
394 kill TMGcRed
395 kill TMGcGreen
396 kill TMGcYellow
397 kill TMGcBlue
398 kill TMGcMagenta
399 kill TMGcCyan
400 kill TMGcGrey
401
402 kill TMGcBRed
403 kill TMGcBGreen
404 kill TMGcBYellow
405 kill TMGcBBlue
406 kill TMGcBMagenta
407 kill TMGcBCyan
408 kill TMGcBGrey
409 kill TMGcWhite
410 kill TMGcFGBWhite
411 quit
412
413ColorBox(SetBG,SetFG)
414 ;"Purpose: to write a grid on the screen, showing all the color combos
415 ;"Input: SetBG -- OPTIONAL. If data sent, then ONLY that background will be shown.
416 ;" (i.e. for only picking a foreground color)
417 ;" SetFG -- OPTIONAL. If data sent, then only for picking background color
418 new fg,bg
419 ;"write "SetBG=",$get(SetBG),!
420 ;"write "SetFG=",$get(SetFG),!
421 if $data(SetFG)#10=0 do
422 . write "FG:",?10
423 . for fg=0:1:15 do
424 . . write $$RJ^XLFSTR(fg,2)," "
425 . write !
426
427 new start,finish
428 set start=0,finish=15
429 if ($data(SetBG)#10=1) do
430 . set (start,finish)=SetBG
431 for bg=start:1:finish do
432 . if bg=0 write "BG:"
433 . write ?7,$$RJ^XLFSTR(bg,2),?10
434 . for fg=0:1:15 do
435 . . do VCOLORS(fg,bg)
436 . . if $data(SetFG)#10=0 do
437 . . . write " X "
438 . . else do
439 . . . write " "
440 . . do VTATRIB(0)
441 . write !
442 quit
443
444Pick1Color(Label,InitValue)
445 ;"Purpose: prompt user to pick a color
446 ;"Input: Label -- Foreground or background
447 ;" InitValue. Value to return if nothing selected.
448 ;"Results: returns value 0-15 if selected, or -1 if abort.
449 new result
450 write "Enter "_Label_" color number (0-15,^ to abort): "
451 read result:$get(DTIME,3600),!
452 if (result="")!(+result'=result)!(+result<0)!(+result>15) set result=+$get(InitValue)
453 quit result
454
455PickFGColor(fg,bg)
456 ;"Purpose: prompt user to pick a foreground color
457 ;"Input -- fg. Value to return if nothing selected.
458 ;"Results: returns value 0-15 if selected, or -1 if abort.
459 do ColorBox(.bg)
460 new result set result=$$Pick1Color("Foreground (FG)",.fg)
461 quit result
462
463PickBGColor(InitValue)
464 ;"Purpose: prompt user to pick a background color
465 ;"Input -- InitValue. Value to return if nothing selected.
466 ;"Results: returns value 0-15 if selected, or -1 if abort.
467 do ColorBox(,1)
468 new result set result=$$Pick1Color("Background (BG)",.InitValue)
469 quit result
470
471PickColors(fg,bg)
472 ;"Purpose: prompt user to pick a FG and BG colors
473 ;"Results: returns value 0-15
474 do ColorBox()
475 set fg=$$Pick1Color("Foreground (FG)",.fg)
476 set bg=$$Pick1Color("Background (BG)",.bg)
477 quit
478
479DemoColors
480 ;"Purpose: to write a lines on the screen, showing all the color combos
481 do VCUSAV2
482 new fg,bg
483 for bg=1:1:14 do
484 . for fg=1:1:14 do
485 . . do VCOLORS(fg,bg)
486 . . write "Text with background color #",bg," and foreground color #",fg
487 . . do VTATRIB(0)
488 . . write !
489 do VCULOAD2
490 quit
491
492
Note: See TracBrowser for help on using the repository browser.