version 1.31, 2003/03/09 15:16:50
|
version 1.39, 2005/01/10 10:30:55
|
Line 1
|
Line 1
|
\ command line edit and history support 16oct94py |
\ command line edit and history support 16oct94py |
|
|
\ Copyright (C) 1995,2000,2003 Free Software Foundation, Inc. |
\ Copyright (C) 1995,2000,2003,2004 Free Software Foundation, Inc. |
|
|
\ This file is part of Gforth. |
\ This file is part of Gforth. |
|
|
Line 48 interpret/compile: ctrl ( "<char>" -- c
|
Line 48 interpret/compile: ctrl ( "<char>" -- c
|
|
|
: bindkey ( xt key -- ) cells ctrlkeys + ! ; |
: bindkey ( xt key -- ) cells ctrlkeys + ! ; |
|
|
' forw ctrl F bindkey |
|
' back ctrl B bindkey |
|
' ?del ctrl H bindkey |
|
' eof ctrl D bindkey |
|
' <del> ctrl X bindkey |
|
|
|
' (ins) IS insert-char |
|
|
|
\ history support 16oct94py |
\ history support 16oct94py |
|
|
0 Value history \ history file fid |
0 Value history \ history file fid |
Line 100 s" os-class" environment? [IF] s" unix"
|
Line 92 s" os-class" environment? [IF] s" unix"
|
: clear-tib ( max span addr pos -- max 0 addr 0 false ) |
: clear-tib ( max span addr pos -- max 0 addr 0 false ) |
clear-line 0 tuck dup ; |
clear-line 0 tuck dup ; |
|
|
: hist-pos ( -- ud ) history file-position throw ; |
: hist-pos ( -- ud ) history file-position drop ( throw ) ; |
: hist-setpos ( ud -- ) history reposition-file throw ; |
: hist-setpos ( ud -- ) history reposition-file drop ( throw ) ; |
|
|
: get-line ( addr len -- len' flag ) |
: get-line ( addr len -- len' flag ) |
swap history read-line throw ; |
swap history read-line throw ; |
Line 129 Create lfpad #lf c,
|
Line 121 Create lfpad #lf c,
|
|
|
: (enter) ( max span addr pos1 -- max span addr pos2 true ) |
: (enter) ( max span addr pos1 -- max span addr pos2 true ) |
>r end^ 2@ hist-setpos |
>r end^ 2@ hist-setpos |
2dup swap history write-line throw |
2dup swap history write-line drop ( throw ) \ don't worry about errors |
hist-pos 2dup backward^ 2! end^ 2! |
hist-pos 2dup backward^ 2! end^ 2! |
r> (ret) ; |
r> (ret) ; |
|
|
Line 193 Create prefix-found 0 , 0 ,
|
Line 185 Create prefix-found 0 , 0 ,
|
REPEAT |
REPEAT |
drop r> ; |
drop r> ; |
|
|
|
: prefix-off ( -- ) 0 0 prefix-found 2! ; |
|
|
: prefix-string ( addr len nfa -- addr' len' ) |
: prefix-string ( addr len nfa -- addr' len' ) |
dup prefix-found ! ?dup |
dup prefix-found ! ?dup |
IF |
IF |
name>string rot /string rot drop |
name>string rot /string rot drop |
dup 1+ prefix-found cell+ ! |
dup 1+ prefix-found cell+ ! |
ELSE |
ELSE |
2drop s" " prefix-found cell+ off |
2drop s" " prefix-off |
THEN ; |
THEN ; |
|
|
: search-prefix ( addr1 len1 -- addr2 len2 ) |
: search-prefix ( addr1 len1 -- addr2 len2 ) |
Line 224 Create prefix-found 0 , 0 ,
|
Line 218 Create prefix-found 0 , 0 ,
|
prefix-found @ IF bl (ins) THEN 0 ; |
prefix-found @ IF bl (ins) THEN 0 ; |
|
|
: kill-prefix ( key -- key ) |
: kill-prefix ( key -- key ) |
dup #tab <> IF 0 0 prefix-found 2! THEN ; |
dup #tab <> IF prefix-off THEN ; |
|
|
|
[IFUNDEF] everyline defer everyline [THEN] |
|
|
|
: 8-bit-io ( -- ) |
|
['] forw ctrl F bindkey |
|
['] back ctrl B bindkey |
|
['] ?del ctrl H bindkey |
|
['] eof ctrl D bindkey |
|
['] <del> ctrl X bindkey |
|
['] next-line ctrl N bindkey |
|
['] prev-line ctrl P bindkey |
|
['] clear-tib ctrl K bindkey |
|
['] first-pos ctrl A bindkey |
|
['] end-pos ctrl E bindkey |
|
['] (enter) #lf bindkey |
|
['] (enter) #cr bindkey |
|
['] tab-expand #tab bindkey |
|
['] (ins) IS insert-char |
|
['] kill-prefix IS everychar |
|
['] noop IS everyline |
|
[ action-of key ] Literal IS key |
|
[ action-of emit ] Literal IS emit ; |
|
|
|
\ UTF-8 support |
|
|
|
require utf-8.fs |
|
|
|
[IFUNDEF] #esc 27 Constant #esc [THEN] |
|
|
|
: save-cursor ( -- ) #esc emit '7 emit ; |
|
: restore-cursor ( -- ) #esc emit '8 emit ; |
|
: .rest ( addr pos1 -- addr pos1 ) |
|
restore-cursor 2dup type ; |
|
: .all ( span addr pos1 -- span addr pos1 ) |
|
restore-cursor >r 2dup swap type r> ; |
|
|
|
: <u8ins> ( max span addr pos1 u8char -- max span addr pos2 ) |
|
>r 2over r@ u8len + u< IF rdrop bell EXIT THEN |
|
>string over r@ u8len + swap move 2dup chars + r@ swap u8!+ drop |
|
r> u8len >r rot r@ chars + -rot r> chars + ; |
|
: (u8ins) ( max span addr pos1 u8char -- max span addr pos2 ) |
|
<u8ins> .all .rest ; |
|
: u8back ( max span addr pos1 -- max span addr pos2 f ) |
|
dup IF over + u8<< over - 0 max .all .rest |
|
ELSE bell THEN 0 ; |
|
: u8forw ( max span addr pos1 -- max span addr pos2 f ) |
|
2 pick over <> IF over + u8@+ u8emit over - ELSE bell THEN 0 ; |
|
: (u8del) ( max span addr pos1 -- max span addr pos2 ) |
|
over + dup u8<< tuck - >r over - |
|
>string over r@ + -rot move |
|
rot r> - -rot ; |
|
: ?u8del ( max span addr pos1 -- max span addr pos2 0 ) |
|
dup IF (u8del) .all 2 spaces .rest THEN 0 ; |
|
: <u8del> ( max span addr pos1 -- max span addr pos2 0 ) |
|
2 pick over <> |
|
IF u8forw drop (u8del) .all 2 spaces .rest |
|
ELSE bell THEN 0 ; |
|
: u8eof 2 pick over or 0= IF bye ELSE <u8del> THEN ; |
|
|
|
: u8first-pos ( max span addr pos1 -- max span addr 0 0 ) |
|
drop 0 .all .rest 0 ; |
|
: u8end-pos ( max span addr pos1 -- max span addr span 0 ) |
|
drop over .all 0 ; |
|
|
|
|
|
: u8clear-line ( max span addr pos1 -- max addr ) |
|
drop restore-cursor swap spaces restore-cursor ; |
|
: u8clear-tib ( max span addr pos -- max 0 addr 0 false ) |
|
u8clear-line 0 tuck dup ; |
|
|
|
: (u8enter) ( max span addr pos1 -- max span addr pos2 true ) |
|
>r end^ 2@ hist-setpos |
|
2dup swap history write-line drop ( throw ) \ don't worry about errors |
|
hist-pos 2dup backward^ 2! end^ 2! |
|
r> .all space true ; |
|
|
|
: u8kill-expand ( max span addr pos1 -- max span addr pos2 ) |
|
prefix-found cell+ @ ?dup IF >r |
|
r@ - >string over r@ + -rot move |
|
rot r@ - -rot .all r> spaces .rest THEN ; |
|
|
|
: insert ( string length buffer size -- ) |
|
rot over min >r r@ - ( left over ) |
|
over dup r@ + rot move r> move ; |
|
|
|
: u8tab-expand ( max span addr pos1 -- max span addr pos2 0 ) |
|
key? IF #tab (u8ins) 0 EXIT THEN |
|
u8kill-expand 2dup extract-word dup 0= IF nip EXIT THEN |
|
search-prefix tib-full? |
|
IF 7 emit 2drop prefix-off |
|
ELSE dup >r |
|
2>r >string r@ + 2r> 2swap insert |
|
r@ + rot r> + -rot |
|
THEN |
|
prefix-found @ IF bl (u8ins) ELSE .all .rest THEN 0 ; |
|
|
|
: utf-8-io ( -- ) |
|
['] u8forw ctrl F bindkey |
|
['] u8back ctrl B bindkey |
|
['] ?u8del ctrl H bindkey |
|
['] u8eof ctrl D bindkey |
|
['] <u8del> ctrl X bindkey |
|
['] u8clear-tib ctrl K bindkey |
|
['] u8first-pos ctrl A bindkey |
|
['] u8end-pos ctrl E bindkey |
|
['] (u8enter) #lf bindkey |
|
['] (u8enter) #cr bindkey |
|
['] u8tab-expand #tab bindkey |
|
['] (u8ins) IS insert-char |
|
['] kill-prefix IS everychar |
|
['] save-cursor IS everyline |
|
['] u8key IS key |
|
['] u8emit IS emit ; |
|
|
|
: utf-8-cold ( -- ) |
|
s" LANG" getenv s" .UTF-8" search nip nip |
|
IF utf-8-io ELSE 8-bit-io THEN ; |
|
|
' kill-prefix IS everychar |
' utf-8-cold INIT8 chained |
|
|
' next-line ctrl N bindkey |
utf-8-cold |
' prev-line ctrl P bindkey |
|
' clear-tib ctrl K bindkey |
|
' first-pos ctrl A bindkey |
|
' end-pos ctrl E bindkey |
|
' (enter) #lf bindkey |
|
' (enter) #cr bindkey |
|
' tab-expand #tab bindkey |
|
|
|
\ initializing history |
\ initializing history |
|
|