pub async fn render(&mut self, state: &State) -> Result<()> {
        match state.last_update() {
            StateUpdate::Query => {
                let display = format!("{}\r{}", clear::CurrentLine, self.prompt.render(state));
                self.write(&display).await?;
            }
            _ => {
                self.list.scroll(state);

                let list_renderer = self.list.render(state);
                let list_len = list_renderer.len();

                // Only add a new line if we are going to print items
                let gauge_separator = if list_len == 0 { "" } else { "\n" };

                let display = format!(
                    "{down}{clrl}\r{gauge}{gauge_sep}{list}{clra}{up}{clrl}\r{prompt}",
                    clrl = clear::CurrentLine,
                    down = cursor::Down(1),
                    gauge = self.gauge.render(state),
                    gauge_sep = gauge_separator,
                    list = list_renderer,
                    clra = clear::AfterCursor,
                    // By going up and printing as the last element the prompt we ensure the cursor
                    // is in the right position
                    up = cursor::Up((list_len + 1) as u16),
                    prompt = self.prompt.render(state),
                );

                self.write(&display).await?;
            }
        }

        Ok(())
    }
/// Update the UI with the given State
///
/// Printing to the terminal is quite expensive, so the whole system tries to reduce
/// the number of prints and allocates a few Strings as possible
Update the UI with the given State
Printing to the terminal is quite expensive, so the whole system tries to reduce
the number of prints and allocates a few Strings as possible
Update the UI with the given State Printing to the terminal is quite expensive so the whole system tries to reduce the number of prints and allocates a few Strings as possible
pub async fn render(&mut self, state: &State) -> Result<()> {
        match state.last_update() {
            StateUpdate::Query => {
                let display = format!("{}\r{}", clear::CurrentLine, self.prompt.render(state));
                self.write(&display).await?;
            }
            _ => {
                self.list.scroll(state);
                let list_renderer = self.list.render(state);
                let list_len = list_renderer.len();
                // Only add a new line if we are going to print items
                let gauge_separator = if list_len == 0 { "" } else { "\n" };
                let display = format!(
                    "{down}{clrl}\r{gauge}{gauge_sep}{list}{clra}{up}{clrl}\r{prompt}",
                    clrl = clear::CurrentLine,
                    down = cursor::Down(1),
                    gauge = self.gauge.render(state),
                    gauge_sep = gauge_separator,
                    list = list_renderer,
                    clra = clear::AfterCursor,
                    // By going up and printing as the last element the prompt we ensure the cursor
                    // is in the right position
                    up = cursor::Up((list_len + 1) as u16),
                    prompt = self.prompt.render(state),
                );
                self.write(&display).await?;
            }
        }
        Ok(())
    }
pub async fn render ( & mut self , state : & State ) -> Result < ( ) > { match state . last_update ( ) { StateUpdate :: Query => { let display = format ! ( " \r " clear CurrentLine self prompt render ( state ) ) ; self . write ( & display ) . await ? ; } _ => { self . list . scroll ( state ) ; let list_renderer = self . list . render ( state ) ; let list_len = list_renderer . len ( ) ; // Only add a new line if we are going to print items let gauge_separator = if list_len == 0 { " " } else { " \n " } ; let display = format ! ( " \r \r " clrl clear CurrentLine down cursor Down ( 1 ) gauge self gauge render ( state ) gauge_sep gauge_separator list list_renderer clra clear AfterCursor // By going up and printing as the last element the prompt we ensure the cursor // is in the right position up cursor Up ( ( list_len 1 ) as u16 ) prompt self prompt render ( state ) ) ; self . write ( & display ) . await ? ; } } Ok ( ( ) ) }
Update the UI with the given State
Printing to the terminal is quite expensive, so the whole system tries to reduce
the number of prints and allocates a few Strings as possible
Update the UI with the given State Printing to the terminal is quite expensive so the whole system tries to reduce the number of prints and allocates a few Strings as possible
&mut self
state
&State