fn _interact_on(&self, term: &Term, allow_quit: bool) -> io::Result<Option<usize>> {
        let mut page = 0;
        let mut capacity = self.items.len();
        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().flat_map(|i| i.split('\n')).collect::<Vec<_>>() {
            let size = &items.len();
            size_vec.push(size.clone());
        }
        loop {
            for (idx, item) in self
                .items
                .iter()
                .enumerate()
                .skip(page * capacity)
                .take(capacity)
            {
                render.selection(
                    item,
                    if sel == idx {
                        SelectionStyle::MenuSelected
                    } else {
                        SelectionStyle::MenuUnselected
                    },
                )?;
            }
            match term.read_key()? {
                Key::ArrowDown | Key::Char('j') => {
                    if sel == !0 {
                        sel = 0;
                    } else {
                        sel = (sel as u64 + 1).rem(self.items.len() as u64) as usize;
                    }
                }
                Key::Escape | Key::Char('q') => {
                    if allow_quit {
                        if self.clear {
                            term.clear_last_lines(self.items.len())?;
                        }
                        return Ok(None);
                    }
                }
                Key::ArrowUp | Key::Char('k') => {
                    if sel == !0 {
                        sel = self.items.len() - 1;
                    } else {
                        sel = ((sel as i64 - 1 + self.items.len() as i64)
                            % (self.items.len() as i64)) as usize;
                    }
                }
                Key::ArrowLeft | Key::Char('h') => {
                    if self.paged {
                        if page == 0 {
                            page = pages - 1;
                        } else {
                            page = page - 1;
                        }
                        sel = page * capacity;
                    }
                }
                Key::ArrowRight | Key::Char('l') => {
                    if self.paged {
                        if page == pages - 1 {
                            page = 0;
                        } else {
                            page = page + 1;
                        }
                        sel = page * capacity;
                    }
                }

                Key::Enter | Key::Char(' ') if sel != !0 => {
                    if self.clear {
                        render.clear()?;
                    }
                    if let Some(ref prompt) = self.prompt {
                        render.single_prompt_selection(prompt, &self.items[sel])?;
                    }
                    return Ok(Some(sel));
                }
                _ => {}
            }
            if 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<usize>> {
        let mut page = 0;
        let mut capacity = self.items.len();
        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().flat_map(|i| i.split('\n')).collect::<Vec<_>>() {
            let size = &items.len();
            size_vec.push(size.clone());
        }
        loop {
            for (idx, item) in self
                .items
                .iter()
                .enumerate()
                .skip(page * capacity)
                .take(capacity)
            {
                render.selection(
                    item,
                    if sel == idx {
                        SelectionStyle::MenuSelected
                    } else {
                        SelectionStyle::MenuUnselected
                    },
                )?;
            }
            match term.read_key()? {
                Key::ArrowDown | Key::Char('j') => {
                    if sel == !0 {
                        sel = 0;
                    } else {
                        sel = (sel as u64 + 1).rem(self.items.len() as u64) as usize;
                    }
                }
                Key::Escape | Key::Char('q') => {
                    if allow_quit {
                        if self.clear {
                            term.clear_last_lines(self.items.len())?;
                        }
                        return Ok(None);
                    }
                }
                Key::ArrowUp | Key::Char('k') => {
                    if sel == !0 {
                        sel = self.items.len() - 1;
                    } else {
                        sel = ((sel as i64 - 1 + self.items.len() as i64)
                            % (self.items.len() as i64)) as usize;
                    }
                }
                Key::ArrowLeft | Key::Char('h') => {
                    if self.paged {
                        if page == 0 {
                            page = pages - 1;
                        } else {
                            page = page - 1;
                        }
                        sel = page * capacity;
                    }
                }
                Key::ArrowRight | Key::Char('l') => {
                    if self.paged {
                        if page == pages - 1 {
                            page = 0;
                        } else {
                            page = page + 1;
                        }
                        sel = page * capacity;
                    }
                }
                Key::Enter | Key::Char(' ') if sel != !0 => {
                    if self.clear {
                        render.clear()?;
                    }
                    if let Some(ref prompt) = self.prompt {
                        render.single_prompt_selection(prompt, &self.items[sel])?;
                    }
                    return Ok(Some(sel));
                }
                _ => {}
            }
            if 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 < usize > > { let mut page = 0 ; let mut capacity = self . items . len ( ) ; 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 ( ) . flat_map ( | i | i . split ( '\n' ) ) . collect :: < Vec < _ > > ( ) { let size = & items . len ( ) ; size_vec . push ( size . clone ( ) ) ; } loop { for ( idx , item ) in self . items . iter ( ) . enumerate ( ) . skip ( page * capacity ) . take ( capacity ) { render . selection ( item , if sel == idx { SelectionStyle :: MenuSelected } else { SelectionStyle :: MenuUnselected } , ) ? ; } match term . read_key ( ) ? { Key :: ArrowDown | Key :: Char ( 'j' ) => { if sel == ! 0 { sel = 0 ; } else { sel = ( sel as u64 + 1 ) . rem ( self . items . len ( ) as u64 ) as usize ; } } Key :: Escape | Key :: Char ( 'q' ) => { if allow_quit { if self . clear { term . clear_last_lines ( self . items . len ( ) ) ? ; } return Ok ( None ) ; } } Key :: ArrowUp | Key :: Char ( 'k' ) => { if sel == ! 0 { sel = self . items . len ( ) - 1 ; } else { sel = ( ( sel as i64 - 1 + self . items . len ( ) as i64 ) % ( self . items . len ( ) as i64 ) ) as usize ; } } Key :: ArrowLeft | Key :: Char ( 'h' ) => { if self . paged { if page == 0 { page = pages - 1 ; } else { page = page - 1 ; } sel = page * capacity ; } } Key :: ArrowRight | Key :: Char ( 'l' ) => { if self . paged { if page == pages - 1 { page = 0 ; } else { page = page + 1 ; } sel = page * capacity ; } } Key :: Enter | Key :: Char ( ' ' ) if sel != ! 0 => { if self . clear { render . clear ( ) ? ; } if let Some ( ref prompt ) = self . prompt { render . single_prompt_selection ( prompt , & self . items [ sel ] ) ? ; } return Ok ( Some ( sel ) ) ; } _ => { } } if 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