home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 95 / af095a.adf / archives / extras.lzx / WebSite / PageText / L04P11.txt < prev    next >
Encoding:
Text File  |  1997-01-18  |  4.9 KB  |  159 lines

  1. L04P11.txtTEXTî®öÆ0®‹g
  2. <p>In hexadecimal a general cursor positioning sequence takes the 
  3. form... 9b [R] [3b C] 48. The first value, 9b hex, is known as the 
  4. control sequence introducer (CSI) and you'll notice in my example 
  5. sequences that I tend to define this value as the variable CSI and then 
  6. use this term rather than the numerical value itself (helps make the 
  7. resulting scripts easier to read). R represents the display row and C the 
  8. display column whilst the 3b hex value is a 'separator' that allows the 
  9. console device to distinguish between  the two real row and column 
  10. parameters. The brackets indicate items that can be treated as 
  11. optional and this means that not only can either row or column positions 
  12. be omitted but the 3b hex separator (which is in fact an ASCII semicolon 
  13. character) only need be provided when either both row and column values
  14. are given or when just a column value is specified. In other words a row 
  15. position on its own can be moved to by sending the simplified three 
  16. character sequence... 9b R 48.</p>
  17.  
  18. <p>With any script that makes more than passing use of cursor positioning 
  19. the best idea is to create an isolated SetCursor() function that takes 
  20. a pair of row/column co-ordinates and sends the appropriate command 
  21. sequence to the console window. Listing 1 shows a typical function and 
  22. you'll notice how the actual row (r) and column (c) values passed to the 
  23. function are easily embedded into the general form of the sequence by 
  24. using the ARexx '||' string concatenation operator. The benefit here is 
  25. that by isolating the cursor positioning code into a separate function 
  26. the main body of your script will be 'cleaner', ie tidier, and therefore 
  27. more understandable to both yourself and anyone else reading your code. 
  28. Cursor position is then performed using statements such as...</p>
  29.  
  30. <pre> 
  31.         call SetCursor(10,0)...</p> 
  32. </pre>
  33.  
  34. <p> Of course it's possible to go one better than this and create 
  35. a function that takes both the cursor position and the text to be 
  36. displayed as function arguments. Listing 2 shows a typical routine 
  37. called CursorWrite() which would, for example, allow you to position 
  38. and write error messages, incidental text and so on using statements 
  39. in the form...</p> 
  40.  
  41. <pre>
  42.         call CursorWrite(10,0,SIGN_ON_MESSAGE)
  43. </pre>
  44.  
  45.  
  46. <H3>Generalising The Code</H3>
  47.  
  48. <p>It's best to try and generalise the routines as much as possible. 
  49. With the listing 2 CursorWrite() routine for example improvements 
  50. could be made. Rather than have the window handle explicitly embedded 
  51. in the function code we could, for instance, pass the window handle to 
  52. the routine as a parameter. Similarly ARexx's Procedure keyword 
  53. could be used to isolate the workings of the routine from any script 
  54. that the routine was finally used in.</p>
  55.     
  56. <p>Listing 3 shows the results of such changes and the benefit is that 
  57. this function can now be incorporated and used in your own code without 
  58. you needing to worry about how it works. Simply make a call to the 
  59. CursorWrite() routine passing your window handle, the row/column screen 
  60. co-ordinates, and text to be printed as function call parameters and 
  61. your text will be duly printed at the specified position. The program 
  62. shown in listing 4 should help get you started. It opens a window and then
  63. just prints a couple of text messages!</p>. 
  64.  
  65. <pre>
  66. <hr>
  67.     SetCursor:
  68.  
  69.     parse arg r,c
  70.  
  71.     call Writech(raw_window,CSI||r||'3b'x||c||'48'x)
  72.  
  73.     return
  74.  
  75.     Listing 1: A simple cursor positioning function
  76.  
  77.  
  78. <hr>
  79.  
  80.     CursorWrite:
  81.  
  82.     parse arg r,c,text$
  83.  
  84.     call Writech(raw_window,CSI||r||'3b'x||c||'48'x)
  85.  
  86.     call Writech(raw_window,text$)
  87.  
  88.     return
  89.  
  90.     Listing 2: Text writing with cursor positioning 
  91.  
  92.  
  93. <hr>
  94.  
  95.     CursorWrite: Procedure
  96.  
  97.     parse arg window,r,c,text$
  98.  
  99.     CSI = '09'x
  100.  
  101.     call Writech(window,CSI||r||'3b'x||c||'48'x)
  102.  
  103.     call Writech(window,text$)
  104.  
  105.     return
  106.  
  107.     Listing 3: A more general form of the CursorWrite() function.
  108.  
  109.  
  110. <hr>
  111.  
  112.  
  113.  
  114.  
  115.         /* ------------------------------------------------ */
  116.  
  117.         /* example.rexx */
  118.  
  119.         MESSAGE1   = 'Just some example text'
  120.  
  121.         MESSAGE2   = 'Hit ANY key to quit program!'
  122.  
  123.         /* ------------------------------------------------ */
  124.  
  125.         call Open(raw_window,'RAW:40/40/480/200/example.rexx')
  126.  
  127.         call CursorWrite(raw_window,10,10,MESSAGE1)
  128.  
  129.         call CursorWrite(raw_window,14,10,MESSAGE2)
  130.  
  131.         keypress$=Readch(raw_window,1) /* wait for keypress */ 
  132.  
  133.         call Close(raw_window)
  134.  
  135.         exit /* logical end of program */
  136.  
  137.         /* ------------------------------------------------ */
  138.  
  139.         CursorWrite: Procedure
  140.  
  141.         parse arg window,r,c,text$
  142.  
  143.         CSI = '9b'x
  144.  
  145.         call Writech(window,CSI||r||'3B'x||c||'48'x)
  146.  
  147.         call Writech(window,text$)
  148.  
  149.         return
  150.  
  151.         /* ------------------------------------------------ */
  152.  
  153. Listing 4: Some runable example code!
  154.  
  155. </pre>
  156.  
  157. <hr>