-
Notifications
You must be signed in to change notification settings - Fork 2
/
block-022.fth
32 lines (31 loc) · 1.47 KB
/
block-022.fth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
printable?( ch--ch 1 | 0 )dup 32 126 btwiif1 else drop 0then;
put-char( ch-- )rc>pos c! dirty mv-rt show! ;
replace-char( ch-- )printable? if put-char then ;
replace-one ( -- ) cur-off red '?' emit key white replace-char ;
insert-char ( ch-- )printable?if0exitthen
>a rc>pos >r row max-col >pos >t
begint@ 1- c@ !t- t@ r@ >while
a> r> c! tdrop mv-rt dirty ;
delete-char( -- )rc>pos >t row max-col >pos >r
begint@ 1+ c@ !t+ t@ r@ <while
32 r> 1- c! dirty tdrop ;
delete-prevmv-lt delete-char ;
eol-offset( row--offset )>t max-col >a
begint@ a@ >pos c@ 32 >ifa@ 1+ atdrop exitthena@-while0 atdrop ;
mv-end( -- )row eol-offset >col ;
clear-line( r-- )0 >pos max-col for 32 over c! 1+ next 0 swap c! dirty ;
clear-eol ( r c-- )max-col over - >t >pos t> for 32 over c! 1+ next drop dirty ;
insert-line( -- ) row max-row <if
row 0 >pos >t t@ t@ cols + max-row 0 >pos t> - cmove>
then row clear-line dirty ;
delete-line( -- ) row max-row <if
row 0 >pos >t t@ cols + >r rows 0 >pos r@ - >a r> t> a> cmove
then max-row clear-line dirty ;
insert-row( r-- )row swap >row insert-line >row ;
delete-row( r-- )row swap >row delete-line >row ;
join-lines( -- )row max-row >=ifexitthen
p1 row 0 >pos s-cpy s-rtrim 32 s-catc
row 1+ 0 >pos s-cat cols 1- + 0 swap c!
row 0 >pos p1 s-cpy drop
row 1+ delete-row ;
open-line( flg-- )ifmv-dntheninsert-line insert-mode! mv-home ;