@@ -64,7 +64,9 @@ pub struct Input<'a, T> {
6464 #[ cfg( feature = "history" ) ]
6565 history : Option < Arc < Mutex < & ' a mut dyn History < T > > > > ,
6666 #[ cfg( feature = "completion" ) ]
67- completion : Option < & ' a dyn Completion > ,
67+ completion : Option < Arc < Mutex < & ' a mut dyn Completion > > > ,
68+ #[ cfg( feature = "completion" ) ]
69+ completion_modified : bool ,
6870}
6971
7072impl < T > Default for Input < ' static , T > {
@@ -164,6 +166,8 @@ impl<'a, T> Input<'a, T> {
164166 history : None ,
165167 #[ cfg( feature = "completion" ) ]
166168 completion : None ,
169+ #[ cfg( feature = "completion" ) ]
170+ completion_modified : false ,
167171 }
168172 }
169173
@@ -219,11 +223,11 @@ impl<'a, T> Input<'a, T> {
219223
220224 /// Enable completion
221225 #[ cfg( feature = "completion" ) ]
222- pub fn completion_with < C > ( mut self , completion : & ' a C ) -> Self
226+ pub fn completion_with < C > ( mut self , completion : & ' a mut C ) -> Self
223227 where
224228 C : Completion ,
225229 {
226- self . completion = Some ( completion) ;
230+ self . completion = Some ( Arc :: new ( Mutex :: new ( completion) ) ) ;
227231 self
228232 }
229233}
@@ -354,6 +358,10 @@ where
354358 }
355359
356360 term. flush ( ) ?;
361+
362+ if self . completion . is_some ( ) {
363+ self . completion_modified = true ;
364+ }
357365 }
358366 Key :: Char ( chr) if !chr. is_ascii_control ( ) => {
359367 chars. insert ( position, chr) ;
@@ -363,6 +371,10 @@ where
363371 term. write_str ( & tail) ?;
364372 term. move_cursor_left ( tail. chars ( ) . count ( ) - 1 ) ?;
365373 term. flush ( ) ?;
374+
375+ if self . completion . is_some ( ) {
376+ self . completion_modified = true ;
377+ }
366378 }
367379 Key :: ArrowLeft if position > 0 => {
368380 if ( position + prompt_len) % term. size ( ) . 1 as usize == 0 {
@@ -473,9 +485,13 @@ where
473485 }
474486 #[ cfg( feature = "completion" ) ]
475487 Key :: ArrowRight | Key :: Tab => {
476- if let Some ( completion) = & self . completion {
488+ if let Some ( completion) = & mut self . completion {
477489 let input: String = chars. clone ( ) . into_iter ( ) . collect ( ) ;
478- if let Some ( x) = completion. get ( & input) {
490+ if let Some ( x) = completion
491+ . lock ( )
492+ . unwrap ( )
493+ . next ( & input, self . completion_modified )
494+ {
479495 term. clear_chars ( chars. len ( ) ) ?;
480496 chars. clear ( ) ;
481497 position = 0 ;
@@ -486,6 +502,8 @@ where
486502 term. write_str ( & x) ?;
487503 term. flush ( ) ?;
488504 }
505+
506+ self . completion_modified = false ;
489507 }
490508 }
491509 #[ cfg( feature = "history" ) ]
0 commit comments