home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vile-os2.zip / pictmode.rc < prev    next >
Text File  |  1995-05-20  |  5KB  |  222 lines

  1. ;                                                                               
  2. ; this procedure implements a primitive ascii picture-drawing mode.  
  3. ;        pgf, may '95
  4.  
  5. ; motions are accomplished with the usual h, j, k, and l keys
  6. ; (the arrow keys do _not_ work here).  in addition, the u, i,
  7. ; n, and m keys will perform diagonal motions.  look at your
  8. ; keyboard to see why these were chosen.
  9.  
  10. ; normally, entering the motion characters (h, j, k, l, u, i, n, m)
  11. ; will draw appropriate box outlines, using the -, |, /, and \ characters.
  12.  
  13. ; lines will be drawn instead with a specific character if the 'c' command
  14. ; is given -- you will be prompted for a character.  this can be
  15. ; cancelled, to revert lines to their "natural" rendition, with the
  16. ; 'C' command.  for example, to draw with a '+' character, you would
  17. ; use "c+" and when finished, would cancel with "C".
  18.  
  19. ; the ^T command will allow you to enter a string of text.  this
  20. ; text will accumulate until ESC, CR, or NL is typed.
  21.  
  22. ; all other input will be inserted as-is, with no cursor movement.  so
  23. ; the space bar can be used to "erase" previously drawn stuff.
  24.  
  25. ; space for the picture must be pre-allocated, with, for example:
  26. ;        80i <ESC>yy24p
  27. ;                                                                           
  28. ; start this up with "run pic"
  29. ; to bind it to a key instead, change it to a "NN store-macro", and
  30. ; then bind "execute-macro NN" to the key you want.
  31. store-procedure replc
  32.     ; never replace a newline 
  33.     ~if &equ $char 0xA
  34.         ~return
  35.     ~endif
  36.  
  37.     ~if &seq %userchar &chr 0
  38.         replace-character %linechar
  39.     ~else
  40.         replace-character %userchar
  41.     ~endif
  42. ~endm
  43. store-procedure pic
  44.     set-variable %keywas &chr 0
  45.     set-variable %userchar &chr 0
  46.     set-variable %linechar &chr 0
  47.     write-message "entering picture, end with ESC"
  48.     redraw-display
  49.     ~while 1
  50.         set-variable %keywas >k
  51.  
  52.         ; was it ESC?  quit if so.
  53.         ~if &seq %keywas &chr 0x1b
  54.             ~break
  55.         ~endif
  56.  
  57.     ; Rectangular Lines:  h, j, k, l
  58.         ~if &seq %keywas h
  59.             ~force backward-character
  60.             set-variable %linechar -
  61.             run replc
  62.             ~goto redraw
  63.         ~endif
  64.         ~if &seq %keywas l
  65.             ~force forward-character
  66.             set-variable %linechar -
  67.             run replc
  68.             ~goto redraw
  69.         ~endif
  70.         ~if &seq %keywas j
  71.             ~force down-line
  72.             set-variable %linechar |
  73.             run replc
  74.             ~goto redraw
  75.         ~endif
  76.         ~if &seq %keywas k
  77.             ~force up-line
  78.             set-variable %linechar |
  79.             run replc
  80.             ~goto redraw
  81.         ~endif
  82.  
  83.     ; Diagonal Lines:  u, i, n, m
  84.         ~if &seq %keywas u
  85.             ~force up-line
  86.             ~force backward-character
  87.             set-variable %linechar \\
  88.             run replc
  89.             ~goto redraw
  90.         ~endif
  91.         ~if &seq %keywas i
  92.             ~force up-line
  93.             ~force forward-character
  94.             set-variable %linechar /
  95.             run replc
  96.             ~goto redraw
  97.         ~endif
  98.         ~if &seq %keywas n
  99.             ~force down-line
  100.             ~force backward-character
  101.             set-variable %linechar /
  102.             run replc
  103.             ~goto redraw
  104.         ~endif
  105.         ~if &seq %keywas m
  106.             ~force down-line
  107.             ~force forward-character
  108.             set-variable %linechar \\
  109.             run replc
  110.             ~goto redraw
  111.         ~endif
  112.  
  113.     ; Rectangular Motions:  ^H, ^L, ^J, ^K
  114.         ; was it ^H
  115.         ~if &seq %keywas &chr 0x8
  116.             ~force backward-character
  117.             ~goto redraw
  118.         ~endif
  119.         
  120.         ; was it ^L
  121.         ~if &seq %keywas &chr 0xC
  122.             ~force forward-character
  123.             ~goto redraw
  124.         ~endif
  125.  
  126.         ; was it ^J
  127.         ~if &seq %keywas &chr 0xA
  128.             ~force down-line
  129.             ~goto redraw
  130.         ~endif
  131.  
  132.         ; was it ^K
  133.         ~if &seq %keywas &chr 0xB
  134.             ~force up-line
  135.             ~goto redraw
  136.         ~endif
  137.     ; Diagonal Motions:  ^U, ^I, ^N, ^M
  138.         ; was it ^U
  139.         ~if &seq %keywas &chr 0x15
  140.             ~force up-line
  141.             ~force backward-character
  142.             ~goto redraw
  143.         ~endif
  144.         ; was it ^I
  145.         ~if &seq %keywas &chr 0x9    
  146.             ~force up-line
  147.             ~force forward-character
  148.             ~goto redraw
  149.         ~endif
  150.         ; was it ^N
  151.         ~if &seq %keywas &chr 0xE
  152.             ~force down-line
  153.             ~force backward-character
  154.             ~goto redraw
  155.         ~endif
  156.         ; was it ^M
  157.         ~if &seq %keywas &chr 0xD
  158.             ~force down-line
  159.             ~force forward-character
  160.             ~goto redraw
  161.         ~endif
  162.  
  163.     ; Text:  ^Ttext to be entered<CR>
  164.         ; was it ^T
  165.         ~if &seq %keywas &chr 0x14
  166.             write-message "entering text, end with CR"
  167.             redraw-display
  168.             set-variable %textkey 0
  169.             ~while 1
  170.                 set-variable %textkey >k
  171.                 ; was it CR (^M)
  172.                 ~if &seq %textkey &chr 0xD
  173.                     ~break
  174.                 ~endif
  175.                 ; was it LF (^J)
  176.                 ~if &seq %textkey &chr 0xA
  177.                     ~break
  178.                 ~endif
  179.                 ; was it ESC (^[)
  180.                 ~if &seq %textkey &chr 0x1B
  181.                     ~break
  182.                 ~endif
  183.                 ; was it BS (^H) or DEL?
  184.                 ~if &or &seq %textkey &chr 0x7f &seq %textkey &chr 0x8
  185.                     ~force backward-character
  186.                     replace-character &chr 0x20
  187.                     ~force backward-character
  188.                     set-variable %textkey &chr $char
  189.                 ~endif
  190.                 replace-character %textkey
  191.                 ~force forward-character
  192.                 redraw-display
  193.             ~endwhile
  194.             write-message "text done, drawing lines again"
  195.             ~goto redraw
  196.         ~endif
  197.  
  198.     ; user-selected lines:  'c' to set the linechar, 'C' to cancel
  199.         ~if &seq %keywas c
  200.             write-message "enter char to draw with: "
  201.             set-variable %userchar >k
  202.             write-message &cat "will draw with: " %userchar
  203.             ~goto redraw
  204.         ~endif
  205.         ~if &seq %keywas C
  206.             write-message "will draw normal lines again"
  207.             set-variable %userchar &chr 0
  208.             ~goto redraw
  209.         ~endif
  210.  
  211.  
  212.     ; Everything else is self inserting
  213.         replace-character %keywas
  214.  
  215.     *redraw
  216.  
  217.         redraw-display
  218.     ~endwhile
  219.     write-message "picture mode done"
  220. ~endm
  221.  
  222.