readline-listener: adding better support for tab completion.
parent
a5b91e181a
commit
92396ffc4b
|
@ -1,12 +1,11 @@
|
|||
! Copyright (C) 2011 Erik Charlebois.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien.data fry io io.encodings.utf8 kernel
|
||||
listener namespaces readline sequences threads vocabs
|
||||
command-line vocabs.hierarchy sequences.deep locals
|
||||
splitting math ;
|
||||
USING: accessors assocs combinators io kernel listener readline
|
||||
sequences splitting threads tools.completion ;
|
||||
IN: readline-listener
|
||||
|
||||
<PRIVATE
|
||||
|
||||
SYMBOL: completions
|
||||
|
||||
TUPLE: readline-reader { prompt initial: f } ;
|
||||
|
@ -19,30 +18,19 @@ M: readline-reader stream-readln
|
|||
M: readline-reader prompt.
|
||||
>>prompt drop ;
|
||||
|
||||
: word-names ( -- strs )
|
||||
all-words [ name>> ] map! ;
|
||||
|
||||
: vocab-names ( -- strs )
|
||||
all-vocabs-recursive filter-vocabs [ name>> ] map! ;
|
||||
|
||||
: prefixed-words ( prefix -- words )
|
||||
'[ _ head? ] word-names swap filter ;
|
||||
|
||||
: prefixed-vocabs ( prefix -- words )
|
||||
'[ _ head? ] vocab-names swap filter ;
|
||||
|
||||
: clear-completions ( -- )
|
||||
f completions tset ;
|
||||
|
||||
: get-completions ( prefix -- completions )
|
||||
completions tget dup [ nip ] [
|
||||
drop current-line " " split1 drop
|
||||
"USING:" = [
|
||||
prefixed-vocabs
|
||||
] [
|
||||
prefixed-words
|
||||
] if dup completions tset
|
||||
] if ;
|
||||
completions tget [ nip ] [
|
||||
current-line " \r\n" split {
|
||||
{ [ dup complete-vocab? ] [ drop vocabs-matching ] }
|
||||
{ [ dup complete-CHAR:? ] [ drop chars-matching ] }
|
||||
{ [ dup complete-COLOR:? ] [ drop colors-matching ] }
|
||||
[ drop words-matching ]
|
||||
} cond values dup completions tset
|
||||
] if* ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: readline-listener ( -- )
|
||||
|
|
Loading…
Reference in New Issue