Commits

crcx committed 8d818d3 Draft

some refactorings, work do do dictionary based lookups

Comments (0)

Files changed (3)

 
 -1 variable: tabAsWhitespace
 
- 0 variable: keymap:enabled
-keymap:enabled data: keymap:enabled
+ 0 variable: keymap
+keymap data: keymap
 "( -a ) Variable, determines whether or not to use the keymap" :doc
 
  0 variable: keymap:PREFIX
 w: remapKeys remapKeys ;
 "( c-c ) Remap one ASCII value to another" :doc
 
-i: ws
+w: remap:whitespace remap:whitespace
    dup,  127 # =if drop,  8 # then
    dup,   13 # =if drop, 10 # then
    remapping # @, 0; drop,
    dup,   10 # =if drop, 32 # then
    tabAsWhitespace # @, 0; drop, dup, 9 # =if drop, 32 # then ;
-( [ c-c ] internal helper for remapping whitespace )
+"( c-c ) helper for remapping whitespace" :doc
 
 w: getc:unfiltered getc:unfiltered 1 # 1 # out, wait 1 # in, ;
 "( -c ) Read a keypress and return the ASCII value on the stack" :doc
 
+w: getc:with/remap getc:with/remap
+  repeat getc:unfiltered remapKeys dup, 0 # !if remap:whitespace ; then drop, again ;
+"( -c ) Read a keypress and return the ASCII value on the stack.\nThis differs from **getc:unfiltered** in that the key value is processed\nby **remapKeys** before being returned.\nUnlike **getc** it does not attempt to support the keymaps." :doc
+
+w: keymap:handler keymap:handler
+  ;
+"( c-c ) handle keymaps" :doc
+
 w: getc getc
-  repeat getc:unfiltered
-  keymap:enabled # @, 0 # !if dup, keymap:PREFIX # @, =if drop, getc:unfiltered keymap:TABLE # +, @, 0; swap, push, do pop, cr 0 # then then
-  remapKeys dup, 0 # !if ws ; then drop, again ;
-"( -c ) Read a keypress and return the ASCII value on the stack.\nThis differs from **getc:unfiltered** in that the key value is processed\nby **remapKeys** before being returned." :doc
+  repeat getc:unfiltered keymap:handler remapKeys dup, 0 # !if remap:whitespace ; then drop, again ;
+"( -c ) Read a keypress and return the ASCII value on the stack.\nBoth remapping and keymaps are handled by this." :doc
 
 i: putc? dup, 8 # =if drop, break # @, ; then dup, putc ;
 ( [ c-c ] helper to display characters and backspaces properly )
   "( - ) List all names in dictionary" :doc
 }}
 
+
+( Keymap ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
+
+{{
+  : dictionary.find/xt ( string:name - xt )  find [ @d->xt ] [ drop #0 ] if ;
+
+  : prefix?
+    dup "keymap:PREFIX" dictionary.find/xt @ == ;
+
+  : seekHandler
+    dup "keymap:TABLE"  dictionary.find/xt + @ ;
+
+  [ prefix? [ drop getc:unfiltered seekHandler dup 0 <> [ dip cr ] [ drop ] if 0 ] ifTrue ] is keymap:handler
+}}
+
 ( Misc. Words ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
 : save     (  -  ) 1 4 out wait ;
 "( - ) Save the image" :doc
 
 ( cleanup and save ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
 global .s save bye
-

retroImage

Binary file modified.
 [ clear ] 'c keymap:TABLE + !
 [ words ] 'w keymap:TABLE + !
 [ .s    ] 's keymap:TABLE + !
-keymap:enabled on
+keymap on