\ LEDIT.SEQ Line Editor Utility by Tom Zimmer comment: Here is a relatively simple editor for editing one line strings. Support is provided for strings up to 126 characters in length, with full word and character operations using keypad or WordStar keys as follows: Ctrl-A Left word Ctrl-S Left character Ctrl-D Right character Ctrl-F Right word Ctrl-G Forward delete Ctrl-T Word delete Ctrl-Y Line delete or clear Left arrow Left character Ctrl-Left arrow Left word Right arrow Right character Ctrl-Right arrow Right word Home Beginning of line End End of line ESC Discard changes and leave Return/Enter Save changes and leave The parameters needed by LINEEDIT are as follows: lineedit ( x y a1 n1 --- ) x = char pos on row, zero = left edge y = row number, zero = top line a1 = counted string n1 = edit limit length, maximum value = 126 Here is an example of a command that would edit a line of text in SAMPLEBUFFER, with a maximum length of 12 characters, at location row 10 column 5 on the screen. 5 10 samplebuffer 12 lineedit comment; only forth also definitions vocabulary leditor leditor also definitions variable lenlimit \ line edit length limit variable editsource \ where the data came from variable insertmode \ insert/overwrite mode flag variable saveflg \ are we saving the results 0 constant ecursor \ edit cursor position 0 constant ex \ where we are editing X 0 constant ey \ where we are editing Y 126 constant maxedit variable editbuf maxedit 2+ allot \ our edit buffer, 126 max editbuf off : .ecursor ( --- ) ex ecursor + ey at ; \ show the cursor : .eline ( --- ) \ redisplay edit line ex ey at editbuf count qtype lenlimit @ editbuf c@ - 0 max spaces ; : ?char ( c1 --- false | c1 ) \ handle normal keys, insert them dup bl '~' between if insertmode @ if editbuf 1+ ecursor + dup 1+ maxedit ecursor - cmove> editbuf c@ 1+ lenlimit c@ min editbuf c! then editbuf 1+ ecursor + c! ecursor 1+ lenlimit @ min =: ecursor ecursor editbuf c@ max editbuf c! 0 2r> 2drop then ; : dohome ( --- ) \ beginning of line 0 =: ecursor ; : doend ( --- ) \ End of line editbuf c@ =: ecursor ; : doright ( --- ) \ right a character ecursor 1+ editbuf c@ min =: ecursor ; : doleft ( --- ) \ left a character ecursor 1- 0 max =: ecursor ; : ( false --- true ) \ flag edit is finished, save changes 0= saveflg on ; : ( false --- true ) \ flag edit is finished, discard chngs 0= saveflg off ; : ( --- ) \ Line delete 0 editbuf c! 0 =: ecursor ; defer doret ' is doret defer dotab ' is dotab defer edone ' is edone defer equit ' is equit defer dopgup ' beep is dopgup defer dopgdn ' beep is dopgdn defer doup ' beep is doup defer dodown ' beep is dodown defer doldel ' is doldel : dofdel ( --- ) \ Forward delete ecursor 1+ editbuf c@ max editbuf c! editbuf 1+ ecursor + dup 1+ swap maxedit ecursor - cmove -1 editbuf c+! ; : >to=bl ( --- ) \ forward to a blank editbuf 1+ dup maxedit + swap ecursor + ?do i c@ bl = ?leave 1 +!> ecursor loop editbuf c@ ecursor min =: ecursor ; : >to<>bl ( --- ) \ forward to a non blank editbuf 1+ dup maxedit + swap ecursor + ?do i c@ bl <> ?leave 1 +!> ecursor loop editbuf c@ ecursor min =: ecursor ; : dorword ( --- ) \ Forward to next word >to=bl >to<>bl ; : ecursor -1 +loop ; : bl ( --- ) \ Back to non blank ecursor 1- 0 max =: ecursor editbuf 1+ dup ecursor + 1- editbuf 1+ max ?do i c@ bl <> ?leave -1 +!> ecursor loop ; : dolword ( --- ) \ back a word bl and while dofdel repeat begin ecursor editbuf c@ < editbuf 1+ ecursor + c@ bl = and while dofdel repeat ; : strip_bl's ( --- ) \ strip blanks from editbuf ecursor >r doend begin doleft editbuf 1+ ecursor + c@ bl = ecursor 0<> and while dofdel repeat editbuf c@ r> min 0 max =: ecursor ; : doins ( --- ) \ toggle insert mode insertmode @ 0= dup insertmode ! if big-cursor else norm-cursor then ; : ?control ( c1 --- bool | c1 ) \ handle control characters dup bl < if 2r> 2drop false swap 31 min exec: \ 0 null 1 a 2 b 3 c 4 d 5 e 6 f beep dolword beep dopgdn doright doup dorword \ 7 g 8 h 9 i LF 11 k 12 l Enter dofdel dobdel dotab beep beep beep doret \ 14 n 15 o 16 p 17 q 18 r 19 s 20 t beep beep beep beep dopgup doleft dowdel \ 21 u 22 v 23 w 24 x 25 y 26 z Esc beep doins beep dodown doldel beep equit \ 28 \ 29 ] 30 ^ 31 _ beep beep beep beep then ; : ?func ( c1 --- bool | c1 ) \ handle function keys dup 127 > if 2r> 2drop false over 243 244 between \ ctrl-left, or ctrl-right if swap 243 = if dolword \ left word else dorword \ right word then else swap 198 - 0 max 14 min exec: \ 198 Home Up PgUp 202 Left 204 beep dohome doup dopgup beep doleft beep \ Right 206 End Down PgDn Insert Delete doright beep doend dodown dopgdn doins dofdel \ 212 beep then then ; \ c1 = keyboard character \ f1 = true for done editing : dokey ( c1 --- f1 ) \ process a key ?char \ handle normal ascii ?func \ function characters ?control \ control chars drop beep 0 ; \ x = char pos on row \ y = line number \ a1 = counted string \ n1 = edit limit length : ( x y a1 n1 --- ) \ Edit line currently in EDITBUF. over c@ ecursor min =: ecursor maxedit min lenlimit ! \ set edit length limit val dup editsource ! editbuf over c@ 1+ lenlimit @ 1+ min cmove editbuf c@ lenlimit @ min editbuf c! =: ey =: ex \ save origin begin .eline .ecursor key dokey ( --- f1 ) until saveflg @ \ proper save exit if strip_bl's editbuf editsource @ over c@ 1+ lenlimit @ 1+ min cmove then ; forth definitions \ x = char pos on row \ y = line number \ a1 = counted string \ n1 = edit limit length : lineedit ( x y a1 n1 --- ) \ Edit line in a1 0 =: ecursor insertmode off ; only forth also definitions \s variable samplebuffer 128 allot : sample ( --- ) " Zimmer, Harold" ">$ samplebuffer over c@ 1+ cmove 27 04 samplebuffer 24 lineedit ;