Hi Tom,

here's a little cursor positioning dialect, I just now
wrote, this is a very simple example, but easier to understand.

REBOL [
   Title: "Cursor positioning dialect"
   author: "Ingo Hohmann"
   email: [EMAIL PROTECTED]
   usage: {
      print cursor2 [ home "My header" pos 13x13 "this starts at 13x13" up 3 "Hey" ]
      print cursor2 [ clear "+" (screen-size/y - 2) "-" "+" "." 
        pos 2x1 "|" (screen-size/y - 2) " " "|" "." 
        pos 3x1 "+" (screen-size/y - 2) "-" "+" ]
   }
   known-bugs: [
      {positioning problem, can't go to first column in the next row, when at end of 
row
       (try to skip the "." in second example
      }
   ]
]

cursor2: func [ 
   [catch] 
   commands [block!] 
   /local screen-size string arg cnt cmd c 
][
   ; get the size of the screen
   screen-size: (      
      c: open/binary [scheme: 'console]
      prin "^(1B)[7n" 
      arg: next next to-string copy c
      close c
      arg: parse/all arg ";R"
      forall arg [change arg to-integer first arg]
      arg: to-pair head arg
   )
   ; some setup
   string: copy ""
   cmd: func [s][join "^(1B)[" s]
   ; compose, so that () get reduced
   commands: compose bind commands 'screen-size
   ; parse the dialect
   arg: parse commands [
      any [
         'direct set arg string! (append string arg) |
         'home                   (append string cmd "H") |
         'kill                   (append string cmd "K") |
         'clear                  (append string cmd "J") |
         'up    set arg integer! (append string cmd [arg "A"]) |
         'down  set arg integer! (append string cmd [arg "B"]) |
         'right set arg integer! (append string cmd [arg "C"]) |
         'left  set arg integer! (append string cmd [arg "D"]) |
         'pos   set arg pair!    (append string cmd [arg/x ";" arg/y "H" ]) |
         'del   set arg integer! (append string cmd [arg "P"]) |
         'space set arg integer! (append string cmd [arg "@"]) |
         'move  set arg pair!    (append string cmd [arg/x ";" arg/y "H" ]) |
         set cnt integer! set arg string! (append string head insert/dup copy "" arg 
cnt) |
         set arg string!         (append string arg)
      ]
   ]
   if not arg [throw make error! "Unable to parse block"]
   ;return string to be printed
   string
]


Once upon a time [EMAIL PROTECTED] spoketh thus:
> Hi,
> 
> The subject says it all. This is the most interesting feature of the
> language and seems to be virtually undocumented. That can't be right can
> it???

Reply via email to