1
- #! /usr/bin/gforth
1
+ #! /usr/bin/env gforth
2
2
( vim: set syntax=colorforth: )
3
3
4
4
\ be2 - a.k.a. Block Editor II
@@ -215,7 +215,7 @@ variable color-stuck
215
215
216
216
( Emit syntax highlighted characters )
217
217
218
- : cemit ( n -- )
218
+ : clemit ( n -- )
219
219
dup color-char-first color-char-last in-range? if
220
220
color-dump
221
221
color-char-first - 1+ dup color-stuck ! fg bl emit exit
@@ -227,7 +227,7 @@ variable color-stuck
227
227
identifier-char? 0= if color-dump then
228
228
;
229
229
230
- : ctype ( a n -- ) 0 ?do dup i + c@ cemit loop drop lf cemit ;
230
+ : cltype ( a n -- ) 0 ?do dup i + c@ clemit loop drop lf clemit ;
231
231
232
232
233
233
@@ -239,7 +239,7 @@ variable color-stuck
239
239
240
240
( Command prompt handling )
241
241
242
- create prompt-text columns allot
242
+ create prompt-text block-size allot ( extra space for cmd line )
243
243
variable prompt-length
244
244
245
245
( workaround bug in history.fs )
@@ -252,15 +252,15 @@ action-of everyline is old-everyline
252
252
: prompt-buffer ( -- a n ) prompt-text columns ;
253
253
: goto-prompt ( -- a n ) 0 screen-lines 1- at-xy prompt-color clear-to-end ;
254
254
: setup-prompt ( -- a n ) goto-prompt prompt-buffer ;
255
+ : prompt+! ( a n -- ) dup >r prompt-text prompt-length @ + swap cmove
256
+ r> prompt-length +! ;
255
257
256
258
: accept-cmd setup-prompt accept prompt-length ! ;
257
259
: edit-cmd setup-prompt prompt-length @ edit-line prompt-length ! ;
258
260
: do-cmd flush prompt-text prompt-length @ ['] evaluate catch drop ;
259
261
260
262
261
263
262
-
263
-
264
264
( Row access )
265
265
266
266
: block-uninit? ( n -- f ) block columns' + 1- c@ lf <> ;
@@ -303,7 +303,7 @@ variable margins-on
303
303
: goto-row ( n -- ) lmargin swap at-xy ;
304
304
: row-string ( n -- a n ) top-row columns rtrim ;
305
305
: finish-row 7 fg clear-to-end ; \ white foreground to show cursor
306
- : print-row ( n -- ) dup goto-row dup row-color row-string ctype finish-row ;
306
+ : print-row ( n -- ) dup goto-row dup row-color row-string cltype finish-row ;
307
307
: park-cursor caret @ columns /mod swap lmargin + swap at-xy ;
308
308
: draw-row ( n -- ) dup left-margin dup print-row right-margin ;
309
309
: draw-rows ( n n -- ) do i draw-row loop ;
@@ -722,18 +722,17 @@ variable clipboard-last
722
722
: handle-key input-mode @ if input-key else navigate-key then refresh ;
723
723
: editor full-refresh begin ekey show handle-key again ;
724
724
725
- : usage s" Usage: be2 [search]" etype ecr 1 (bye) ;
726
- : arg-check argc @ 2 > if usage then ;
727
-
725
+ : arg-cmd s" " prompt!
726
+ begin next-arg 2dup 0 0 d<> while s" " prompt+! prompt+!
727
+ repeat 2drop do-cmd ;
728
728
: block-filename ( -- a n)
729
729
s" BE2_BLOCKS" getenv dup 0= if 2drop 0 filename-length !
730
730
s" PWD" getenv +filename s" /.be2_blocks" +filename filename@ then ;
731
731
: setup-blocks
732
732
0 block-offset !
733
733
block-filename open-blocks
734
734
update-row-count
735
- arg-check
736
- argc @ 2 >= if 1 arg search! search-for flush-top then
735
+ arg-cmd
737
736
;
738
737
: main setup-blocks editor ;
739
738
: reset-terminal normal page ;
0 commit comments