fn _interact_on(&self, term: &Term, allow_quit: bool) -> io::Result<Option<String>> {
        let mut page = 0;
        let mut capacity = self.items.len();
        let mut search_term = String::new();
        if self.paged {
            capacity = (term.size().0 as usize) / self.lines_per_item - self.offset;
        }
        let pages = (self.items.len() / capacity) + 1;
        let mut render = TermThemeRenderer::new(term, self.theme);
        let mut sel = self.default;
        if let Some(ref prompt) = self.prompt {
            render.prompt(prompt)?;
        }
        let mut size_vec = Vec::new();
        for items in self.items.iter().as_slice() {
            let size = &items.len();
            size_vec.push(size.clone());
        }
        loop {
            let regexp_str = format!(r"{}\w+", search_term); 
            let re = Regex::new(&regexp_str).unwrap();

            let filtered_list: Vec<&String> = self
                .items
                .iter()
                .filter(|item| if self.ignore_casing { 
                    re.is_match(&item.to_lowercase())
                } else {
                    re.is_match(item)
                })
                .collect();

            capacity = filtered_list.len();
            if self.paged {
                capacity = (term.size().0 as usize) / self.lines_per_item - self.offset;
            }
            
            for (idx, item) in filtered_list
                .iter()
                .enumerate()
                .skip(page * capacity)
                .take(capacity)
            {
                render.selection(
                    item,
                    if sel == idx {
                        SelectionStyle::MenuSelected
                    } else {
                        SelectionStyle::MenuUnselected
                    },
                )?;
            }
            match term.read_key()? {
                Key::ArrowDown => {
                    if sel == !0 {
                        sel = 0;
                    } else {
                        sel = (sel as u64 + 1).rem(filtered_list.len() as u64) as usize;
                    }
                }
                Key::Escape => {
                    if allow_quit {
                        if self.clear {
                            term.clear_last_lines(filtered_list.len())?;
                        }
                        return Ok(None);
                    }
                }
                Key::ArrowUp if filtered_list.len() > 0 => {
                    if sel == !0 {
                        sel = filtered_list.len() - 1;
                    } else {
                        sel = ((sel as i64 - 1 + filtered_list.len() as i64)
                            % (filtered_list.len() as i64)) as usize;
                    }
                }
                Key::ArrowLeft => {
                    if self.paged {
                        if page == 0 {
                            page = pages - 1;
                        } else {
                            page = page - 1;
                        }
                        sel = page * capacity;
                    }
                }
                Key::ArrowRight => {
                    if self.paged {
                        if page == pages - 1 {
                            page = 0;
                        } else {
                            page = page + 1;
                        }
                        sel = page * capacity;
                    }
                }

                Key::Enter if filtered_list.len() > 0 => {
                    if self.clear {
                        render.clear()?;
                    }
                    if let Some(ref prompt) = self.prompt {
                        render.single_prompt_selection(prompt, &filtered_list[sel])?;
                    }
                    return Ok(Some(filtered_list[sel].to_owned()));
                },
                Key::Backspace => {
                    search_term.pop();
                },
                Key::Char(key) => {
                    if self.ignore_casing {
                        search_term.push(key.to_lowercase().to_string().pop().unwrap());
                    } else { 
                        search_term.push(key);
                    }
                    sel = 0;
                },
                _ => {}
            }
            if filtered_list.len() > 0 && (sel < page * capacity || sel >= (page + 1) * capacity) {
                page = sel / capacity;
            }
            render.clear_preserve_prompt(&size_vec)?;
        }
    }
/// Like `interact` but allows a specific terminal to be set.
Like `interact` but allows a specific terminal to be set.
Like ` interact ` but allows a specific terminal to be set .
fn _interact_on(&self, term: &Term, allow_quit: bool) -> io::Result<Option<String>> {
        let mut page = 0;
        let mut capacity = self.items.len();
        let mut search_term = String::new();
        if self.paged {
            capacity = (term.size().0 as usize) / self.lines_per_item - self.offset;
        }
        let pages = (self.items.len() / capacity) + 1;
        let mut render = TermThemeRenderer::new(term, self.theme);
        let mut sel = self.default;
        if let Some(ref prompt) = self.prompt {
            render.prompt(prompt)?;
        }
        let mut size_vec = Vec::new();
        for items in self.items.iter().as_slice() {
            let size = &items.len();
            size_vec.push(size.clone());
        }
        loop {
            let regexp_str = format!(r"{}\w+", search_term); 
            let re = Regex::new(&regexp_str).unwrap();
            let filtered_list: Vec<&String> = self
                .items
                .iter()
                .filter(|item| if self.ignore_casing { 
                    re.is_match(&item.to_lowercase())
                } else {
                    re.is_match(item)
                })
                .collect();
            capacity = filtered_list.len();
            if self.paged {
                capacity = (term.size().0 as usize) / self.lines_per_item - self.offset;
            }
            for (idx, item) in filtered_list
                .iter()
                .enumerate()
                .skip(page * capacity)
                .take(capacity)
            {
                render.selection(
                    item,
                    if sel == idx {
                        SelectionStyle::MenuSelected
                    } else {
                        SelectionStyle::MenuUnselected
                    },
                )?;
            }
            match term.read_key()? {
                Key::ArrowDown => {
                    if sel == !0 {
                        sel = 0;
                    } else {
                        sel = (sel as u64 + 1).rem(filtered_list.len() as u64) as usize;
                    }
                }
                Key::Escape => {
                    if allow_quit {
                        if self.clear {
                            term.clear_last_lines(filtered_list.len())?;
                        }
                        return Ok(None);
                    }
                }
                Key::ArrowUp if filtered_list.len() > 0 => {
                    if sel == !0 {
                        sel = filtered_list.len() - 1;
                    } else {
                        sel = ((sel as i64 - 1 + filtered_list.len() as i64)
                            % (filtered_list.len() as i64)) as usize;
                    }
                }
                Key::ArrowLeft => {
                    if self.paged {
                        if page == 0 {
                            page = pages - 1;
                        } else {
                            page = page - 1;
                        }
                        sel = page * capacity;
                    }
                }
                Key::ArrowRight => {
                    if self.paged {
                        if page == pages - 1 {
                            page = 0;
                        } else {
                            page = page + 1;
                        }
                        sel = page * capacity;
                    }
                }
                Key::Enter if filtered_list.len() > 0 => {
                    if self.clear {
                        render.clear()?;
                    }
                    if let Some(ref prompt) = self.prompt {
                        render.single_prompt_selection(prompt, &filtered_list[sel])?;
                    }
                    return Ok(Some(filtered_list[sel].to_owned()));
                },
                Key::Backspace => {
                    search_term.pop();
                },
                Key::Char(key) => {
                    if self.ignore_casing {
                        search_term.push(key.to_lowercase().to_string().pop().unwrap());
                    } else { 
                        search_term.push(key);
                    }
                    sel = 0;
                },
                _ => {}
            }
            if filtered_list.len() > 0 && (sel < page * capacity || sel >= (page + 1) * capacity) {
                page = sel / capacity;
            }
            render.clear_preserve_prompt(&size_vec)?;
        }
    }
fn _interact_on ( & self , term : & Term , allow_quit : bool ) -> io :: Result < Option < String > > { let mut page = 0 ; let mut capacity = self . items . len ( ) ; let mut search_term = String :: new ( ) ; if self . paged { capacity = ( term . size ( ) . 0 as usize ) / self . lines_per_item - self . offset ; } let pages = ( self . items . len ( ) / capacity ) + 1 ; let mut render = TermThemeRenderer :: new ( term , self . theme ) ; let mut sel = self . default ; if let Some ( ref prompt ) = self . prompt { render . prompt ( prompt ) ? ; } let mut size_vec = Vec :: new ( ) ; for items in self . items . iter ( ) . as_slice ( ) { let size = & items . len ( ) ; size_vec . push ( size . clone ( ) ) ; } loop { let regexp_str = format ! ( r"{}\w+" search_term ) ; let re = Regex :: new ( & regexp_str ) . unwrap ( ) ; let filtered_list : Vec < & String > = self . items . iter ( ) . filter ( | item | if self . ignore_casing { re . is_match ( & item . to_lowercase ( ) ) } else { re . is_match ( item ) } ) . collect ( ) ; capacity = filtered_list . len ( ) ; if self . paged { capacity = ( term . size ( ) . 0 as usize ) / self . lines_per_item - self . offset ; } for ( idx , item ) in filtered_list . iter ( ) . enumerate ( ) . skip ( page * capacity ) . take ( capacity ) { render . selection ( item , if sel == idx { SelectionStyle :: MenuSelected } else { SelectionStyle :: MenuUnselected } , ) ? ; } match term . read_key ( ) ? { Key :: ArrowDown => { if sel == ! 0 { sel = 0 ; } else { sel = ( sel as u64 + 1 ) . rem ( filtered_list . len ( ) as u64 ) as usize ; } } Key :: Escape => { if allow_quit { if self . clear { term . clear_last_lines ( filtered_list . len ( ) ) ? ; } return Ok ( None ) ; } } Key :: ArrowUp if filtered_list . len ( ) > 0 => { if sel == ! 0 { sel = filtered_list . len ( ) - 1 ; } else { sel = ( ( sel as i64 - 1 + filtered_list . len ( ) as i64 ) % ( filtered_list . len ( ) as i64 ) ) as usize ; } } Key :: ArrowLeft => { if self . paged { if page == 0 { page = pages - 1 ; } else { page = page - 1 ; } sel = page * capacity ; } } Key :: ArrowRight => { if self . paged { if page == pages - 1 { page = 0 ; } else { page = page + 1 ; } sel = page * capacity ; } } Key :: Enter if filtered_list . len ( ) > 0 => { if self . clear { render . clear ( ) ? ; } if let Some ( ref prompt ) = self . prompt { render . single_prompt_selection ( prompt , & filtered_list [ sel ] ) ? ; } return Ok ( Some ( filtered_list [ sel ] . to_owned ( ) ) ) ; } , Key :: Backspace => { search_term . pop ( ) ; } , Key :: Char ( key ) => { if self . ignore_casing { search_term . push ( key . to_lowercase ( ) . to_string ( ) . pop ( ) . unwrap ( ) ) ; } else { search_term . push ( key ) ; } sel = 0 ; } , _ => { } } if filtered_list . len ( ) > 0 && ( sel < page * capacity || sel >= ( page + 1 ) * capacity ) { page = sel / capacity ; } render . clear_preserve_prompt ( & size_vec ) ? ; } }
Like `interact` but allows a specific terminal to be set.
Like ` interact ` but allows a specific terminal to be set .
&self
term
&Term
allow_quit
bool