--- gforth/history.fs 2006/12/31 13:39:13 1.50 +++ gforth/history.fs 2007/05/05 17:30:23 1.53 @@ -198,14 +198,32 @@ require utf-8.fs [IFUNDEF] #esc 27 Constant #esc [THEN] -: save-cursor ( -- ) #esc emit '7 emit ; -: restore-cursor ( -- ) #esc emit '8 emit ; +Variable curpos + +: at-xy? ( -- x y ) + key? drop + #esc emit ." [6n" 0 0 + BEGIN key dup 'R <> WHILE + dup '; = IF drop swap ELSE + dup '0 '9 1+ within IF '0 - swap 10 * + ELSE + drop THEN THEN + REPEAT drop 1- swap 1- ; +: cursor@ ( -- n ) at-xy? form nip * + ; +: cursor! ( n -- ) form nip /mod at-xy ; +: cur-correct ( addr u -- ) x-width curpos @ + cursor@ - + form nip >r r@ 2/ + r@ / r> * negate curpos +! ; + +: save-cursor ( -- ) cursor@ curpos ! ; +: restore-cursor ( -- ) curpos @ cursor! ; : .rest ( addr pos1 -- addr pos1 ) - restore-cursor 2dup type ; + key? ?EXIT + restore-cursor 2dup type 2dup cur-correct ; : .all ( span addr pos1 -- span addr pos1 ) - restore-cursor >r 2dup swap type r> ; + key? ?EXIT + restore-cursor >r 2dup swap type 2dup swap cur-correct r> ; : xback-restore ( u -- ) - drop restore-cursor ; + drop key? ?EXIT + restore-cursor ; \ In the following, addr max is the buffer, addr span is the current \ string in the buffer, and pos1 is the cursor position in the buffer.