readline-listener: change matching to use prefixed.

db4
John Benediktsson 2012-09-25 09:37:50 -07:00
parent 92396ffc4b
commit 6303ed9106
2 changed files with 25 additions and 8 deletions

View File

@ -1,7 +1,8 @@
! 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 assocs combinators io kernel listener readline USING: accessors assocs colors.constants combinators fry io
sequences splitting threads tools.completion ; kernel listener readline sequences splitting threads
tools.completion unicode.data vocabs vocabs.hierarchy ;
IN: readline-listener IN: readline-listener
<PRIVATE <PRIVATE
@ -21,14 +22,29 @@ M: readline-reader prompt.
: clear-completions ( -- ) : clear-completions ( -- )
f completions tset ; f completions tset ;
: prefixed ( prefix seq -- seq' )
swap '[ _ head? ] filter ;
: prefixed-words ( prefix -- words )
all-words [ name>> ] map! prefixed ;
: prefixed-vocabs ( prefix -- vocabs )
all-vocabs-recursive filter-vocabs [ name>> ] map! prefixed ;
: prefixed-colors ( prefix -- colors )
named-colors prefixed ;
: prefixed-chars ( prefix -- chars )
name-map keys prefixed ;
: get-completions ( prefix -- completions ) : get-completions ( prefix -- completions )
completions tget [ nip ] [ completions tget [ nip ] [
current-line " \r\n" split { current-line " \r\n" split {
{ [ dup complete-vocab? ] [ drop vocabs-matching ] } { [ dup complete-vocab? ] [ drop prefixed-vocabs ] }
{ [ dup complete-CHAR:? ] [ drop chars-matching ] } { [ dup complete-CHAR:? ] [ drop prefixed-chars ] }
{ [ dup complete-COLOR:? ] [ drop colors-matching ] } { [ dup complete-COLOR:? ] [ drop prefixed-colors ] }
[ drop words-matching ] [ drop prefixed-words ]
} cond values dup completions tset } cond dup completions tset
] if* ; ] if* ;
PRIVATE> PRIVATE>

View File

@ -21,7 +21,8 @@ STRUCT: HIST_ENTRY
{ timestamp c-string } { timestamp c-string }
{ data histdata_t } ; { data histdata_t } ;
: HISTENT_BYTES ( hs -- n ) [ line>> strlen ] [ timestamp>> strlen ] bi + ; inline : HISTENT_BYTES ( hs -- n )
[ line>> strlen ] [ timestamp>> strlen ] bi + ; inline
STRUCT: HISTORY_STATE STRUCT: HISTORY_STATE
{ entries HIST_ENTRY** } { entries HIST_ENTRY** }