diff --git a/femto.tal b/femto.tal index ebeb64f..19961c5 100644 --- a/femto.tal +++ b/femto.tal @@ -114,6 +114,7 @@ ] @state [ + &key $1 ( last key read ) &saw-esc $1 ( did we just see ESC? ) &saw-xterm $1 ( did we just see an ESC [ xterm sequence? ) &saw-vt $1 ( did we just see an ESC [ $N vt sequence? ) @@ -204,9 +205,10 @@ JMP2r @receive-terminal-size ( -> ) - .Console/read DEI .tmp/pos LDZ2 STA + .Console/read DEI .state/key STZ + .state/key LDZ .tmp/pos LDZ2 STA .tmp/pos LDZ2 INC2 .tmp/pos STZ2 - .Console/read DEI LIT 'R EQU ;parse-terminal-size JCN2 + .state/key LDZ LIT 'R EQU ;parse-terminal-size JCN2 BRK @parse-terminal-size ( -> ) @@ -619,13 +621,14 @@ ( maybe M-% for search&replace ) @on-key-escaped ( -> ) #00 .state/saw-esc STZ - .Console/read DEI LIT '< EQU ( M-< ) ;goto-start JCN2 - .Console/read DEI LIT '> EQU ( M-> ) ;goto-end JCN2 - .Console/read DEI LIT 'c EQU ( M-c ) ;toggle-color JCN2 - .Console/read DEI LIT 'g EQU ( M-g ) ;goto-line JCN2 - .Console/read DEI LIT 't EQU ( M-t ) ;toggle-tabs JCN2 - .Console/read DEI LIT 'v EQU ( M-v ) ;page-up JCN2 - .Console/read DEI LIT '[ EQU ( M-[ ) ;xterm JCN2 + .Console/read DEI .state/key STZ + .state/key LDZ LIT '< EQU ( M-< ) ;goto-start JCN2 + .state/key LDZ LIT '> EQU ( M-> ) ;goto-end JCN2 + .state/key LDZ LIT 'c EQU ( M-c ) ;toggle-color JCN2 + .state/key LDZ LIT 'g EQU ( M-g ) ;goto-line JCN2 + .state/key LDZ LIT 't EQU ( M-t ) ;toggle-tabs JCN2 + .state/key LDZ LIT 'v EQU ( M-v ) ;page-up JCN2 + .state/key LDZ LIT '[ EQU ( M-[ ) ;xterm JCN2 BRK @xterm @@ -657,15 +660,16 @@ @on-key-xterm ( -> ) #00 .state/saw-xterm STZ - .Console/read DEI LIT 'A EQU ( ^[[A -> up ) ;up JCN2 - .Console/read DEI LIT 'B EQU ( ^[[B -> down ) ;down JCN2 - .Console/read DEI LIT 'C EQU ( ^[[C -> right ) ;forward JCN2 - .Console/read DEI LIT 'D EQU ( ^[[D -> left ) ;back JCN2 - .Console/read DEI LIT 'F EQU ( ^[[F -> end ) ;eol JCN2 - .Console/read DEI LIT 'H EQU ( ^[[H -> home ) ;bol JCN2 - .Console/read DEI LIT '0 LTH ;ignore JCN2 - .Console/read DEI LIT '8 GTH ;ignore JCN2 - .Console/read DEI .state/saw-vt STZ ( ^[[1 through ^[[8 ) + .Console/read DEI .state/key STZ + .state/key LDZ LIT 'A EQU ( ^[[A -> up ) ;up JCN2 + .state/key LDZ LIT 'B EQU ( ^[[B -> down ) ;down JCN2 + .state/key LDZ LIT 'C EQU ( ^[[C -> right ) ;forward JCN2 + .state/key LDZ LIT 'D EQU ( ^[[D -> left ) ;back JCN2 + .state/key LDZ LIT 'F EQU ( ^[[F -> end ) ;eol JCN2 + .state/key LDZ LIT 'H EQU ( ^[[H -> home ) ;bol JCN2 + .state/key LDZ LIT '0 LTH ;ignore JCN2 + .state/key LDZ LIT '8 GTH ;ignore JCN2 + .state/key LDZ .state/saw-vt STZ ( ^[[1 through ^[[8 ) BRK @clear-line ( -> ) @@ -688,19 +692,21 @@ @move-to-prev-match BRK @on-key-searching - .Console/read DEI #07 EQU ( C-g ) ;cancel-search JCN2 - .Console/read DEI #0d EQU ( \r ) ;finish-search JCN2 - .Console/read DEI #6e EQU ( n ) ;move-to-next-match JCN2 - .Console/read DEI #70 EQU ( p ) ;move-to-prev-match JCN2 + .Console/read DEI .state/key STZ + .state/key LDZ #07 EQU ( C-g ) ;cancel-search JCN2 + .state/key LDZ #0d EQU ( \r ) ;finish-search JCN2 + .state/key LDZ #6e EQU ( n ) ;move-to-next-match JCN2 + .state/key LDZ #70 EQU ( p ) ;move-to-prev-match JCN2 ;ignore JMP2 @on-key-prompt - .Console/read DEI #07 EQU ( C-g ) ;cancel-prompt JCN2 - .Console/read DEI #0d EQU ( \r ) ;finish-prompt JCN2 - .Console/read DEI #7f EQU ( DEL ) ;backspace-prompt JCN2 - .Console/read DEI #20 LTH ;ignore JCN2 ( ignore for now ) - .Console/read DEI #7e GTH ;ignore JCN2 ( ignore for now ) - .Console/read DEI ( printable ASCII ) ;insert-prompt JMP2 + .Console/read DEI .state/key STZ + .state/key LDZ #07 EQU ( C-g ) ;cancel-prompt JCN2 + .state/key LDZ #0d EQU ( \r ) ;finish-prompt JCN2 + .state/key LDZ #7f EQU ( DEL ) ;backspace-prompt JCN2 + .state/key LDZ #20 LTH ;ignore JCN2 ( ignore for now ) + .state/key LDZ #7e GTH ;ignore JCN2 ( ignore for now ) + .state/key LDZ ( printable ASCII ) ;insert-prompt JMP2 BRK ( TODO: C-h for help ) @@ -713,27 +719,27 @@ .state/saw-vt LDZ ;on-key-vt JCN2 .state/saw-xterm LDZ ;on-key-xterm JCN2 .state/saw-esc LDZ ;on-key-escaped JCN2 - .Console/read DEI #01 EQU ( C-a ) ;bol JCN2 - .Console/read DEI #02 EQU ( C-b ) ;back JCN2 - .Console/read DEI #04 EQU ( C-d ) ;delete JCN2 - .Console/read DEI #05 EQU ( C-e ) ;eol JCN2 - .Console/read DEI #06 EQU ( C-f ) ;forward JCN2 - .Console/read DEI #09 EQU ( \t ) ;insert-tab JCN2 - .Console/read DEI #0c EQU ( C-l ) ;center-view JCN2 - .Console/read DEI #0d EQU ( \r ) ;newline JCN2 - .Console/read DEI #0e EQU ( C-n ) ;down JCN2 - .Console/read DEI #0f EQU ( C-o ) ;save JCN2 - .Console/read DEI #10 EQU ( C-p ) ;up JCN2 - .Console/read DEI #13 EQU ( C-s ) ;search JCN2 - .Console/read DEI #16 EQU ( C-v ) ;page-down JCN2 - .Console/read DEI #18 EQU ( C-x ) ;quit JCN2 - .Console/read DEI #1a EQU ( C-z ) ;debug JCN2 - .Console/read DEI #1b EQU ( ESC ) ;escape JCN2 - .Console/read DEI #7f EQU ( DEL ) ;backspace JCN2 - .Console/read DEI #20 LTH ;ignore JCN2 ( ignore for now ) - .Console/read DEI #7e GTH ;ignore JCN2 ( ignore for now ) - .Console/read DEI ( printable ASCII ) ;insert JMP2 - BRK + .Console/read DEI .state/key STZ + .state/key LDZ #01 EQU ( C-a ) ;bol JCN2 + .state/key LDZ #02 EQU ( C-b ) ;back JCN2 + .state/key LDZ #04 EQU ( C-d ) ;delete JCN2 + .state/key LDZ #05 EQU ( C-e ) ;eol JCN2 + .state/key LDZ #06 EQU ( C-f ) ;forward JCN2 + .state/key LDZ #09 EQU ( \t ) ;insert-tab JCN2 + .state/key LDZ #0c EQU ( C-l ) ;center-view JCN2 + .state/key LDZ #0d EQU ( \r ) ;newline JCN2 + .state/key LDZ #0e EQU ( C-n ) ;down JCN2 + .state/key LDZ #0f EQU ( C-o ) ;save JCN2 + .state/key LDZ #10 EQU ( C-p ) ;up JCN2 + .state/key LDZ #13 EQU ( C-s ) ;search JCN2 + .state/key LDZ #16 EQU ( C-v ) ;page-down JCN2 + .state/key LDZ #18 EQU ( C-x ) ;quit JCN2 + .state/key LDZ #1a EQU ( C-z ) ;debug JCN2 + .state/key LDZ #1b EQU ( ESC ) ;escape JCN2 + .state/key LDZ #7f EQU ( DEL ) ;backspace JCN2 + .state/key LDZ #20 LTH ;ignore JCN2 ( ignore for now ) + .state/key LDZ #7e GTH ;ignore JCN2 ( ignore for now ) + .state/key LDZ ( printable ASCII ) ;insert JMP2 @min2 ( x* y* -> min* ) LTH2k JMP SWP2 POP2 JMP2r