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