pub async fn task<W>(config: Config, outbound: W, mut recv: Receiver<Event>) -> Result<Option<Text>>
where
    W: io::Write + Send + Unpin + 'static,
{
    log::trace!("starting screen");

    let mut last_timestamp = Instant::now();
    let mut render: bool;
    let mut selection = None;

    let mut state = State::new();
    let mut canvas = Canvas::new(&config, outbound).await?;

    canvas.render(&state).await?;

    while let Some(event) = recv.next().await {
        render = false;

        match event {
            Event::Search(prompt) => {
                log::trace!("printing prompt: {:?}", prompt);

                last_timestamp = prompt.timestamp();
                state.set_search(prompt);
                render = true;
            }

            Event::Flush((matches, len)) => {
                log::trace!("flushing matches");

                // Flush happens when the pool size
                // changes or the pool is complete
                state.set_matches((matches, len));
                render = true;
            }

            Event::SearchDone((matches, len, timestamp)) => {
                // Only if the search timestamp is the same as the last query timestamp
                // we will update the state. This way we will drop any intermediate search
                // and reduce the number of renders
                if timestamp >= last_timestamp {
                    log::trace!("printing new search results");

                    state.set_matches((matches, len));
                    render = true;
                }
            }

            Event::Up => {
                log::trace!("moving selection up");

                state.select_up();
                render = true;
            }
            Event::Down => {
                log::trace!("moving selection down");

                state.select_down();
                render = true;
            }

            Event::Done => {
                selection = state.selection();
                break;
            }
            Event::Exit => break,

            _ => (),
        };

        if render {
            canvas.render(&state).await?;
        }
    }

    log::trace!("screen done");

    Ok(selection)
}
/// Run the screen's task
Run the screen's task
Run the screen ' s task
pub async fn task<W>(config: Config, outbound: W, mut recv: Receiver<Event>) -> Result<Option<Text>>
where
    W: io::Write + Send + Unpin + 'static,
{
    log::trace!("starting screen");
    let mut last_timestamp = Instant::now();
    let mut render: bool;
    let mut selection = None;
    let mut state = State::new();
    let mut canvas = Canvas::new(&config, outbound).await?;
    canvas.render(&state).await?;
    while let Some(event) = recv.next().await {
        render = false;
        match event {
            Event::Search(prompt) => {
                log::trace!("printing prompt: {:?}", prompt);
                last_timestamp = prompt.timestamp();
                state.set_search(prompt);
                render = true;
            }
            Event::Flush((matches, len)) => {
                log::trace!("flushing matches");
                // Flush happens when the pool size
                // changes or the pool is complete
                state.set_matches((matches, len));
                render = true;
            }
            Event::SearchDone((matches, len, timestamp)) => {
                // Only if the search timestamp is the same as the last query timestamp
                // we will update the state. This way we will drop any intermediate search
                // and reduce the number of renders
                if timestamp >= last_timestamp {
                    log::trace!("printing new search results");
                    state.set_matches((matches, len));
                    render = true;
                }
            }
            Event::Up => {
                log::trace!("moving selection up");
                state.select_up();
                render = true;
            }
            Event::Down => {
                log::trace!("moving selection down");
                state.select_down();
                render = true;
            }
            Event::Done => {
                selection = state.selection();
                break;
            }
            Event::Exit => break,
            _ => (),
        };
        if render {
            canvas.render(&state).await?;
        }
    }
    log::trace!("screen done");
    Ok(selection)
}
pub async fn task < W > ( config : Config , outbound : W , mut recv : Receiver < Event > ) -> Result < Option < Text > > where W : io :: Write + Send + Unpin + ' static , { log :: trace ! ( " " ) ; let mut last_timestamp = Instant :: now ( ) ; let mut render : bool ; let mut selection = None ; let mut state = State :: new ( ) ; let mut canvas = Canvas :: new ( & config , outbound ) . await ? ; canvas . render ( & state ) . await ? ; while let Some ( event ) = recv . next ( ) . await { render = false ; match event { Event :: Search ( prompt ) => { log :: trace ! ( " " prompt ) ; last_timestamp = prompt . timestamp ( ) ; state . set_search ( prompt ) ; render = true ; } Event :: Flush ( ( matches , len ) ) => { log :: trace ! ( " " ) ; // Flush happens when the pool size // changes or the pool is complete state . set_matches ( ( matches , len ) ) ; render = true ; } Event :: SearchDone ( ( matches , len , timestamp ) ) => { // Only if the search timestamp is the same as the last query timestamp // we will update the state. This way we will drop any intermediate search // and reduce the number of renders if timestamp >= last_timestamp { log :: trace ! ( " " ) ; state . set_matches ( ( matches , len ) ) ; render = true ; } } Event :: Up => { log :: trace ! ( " " ) ; state . select_up ( ) ; render = true ; } Event :: Down => { log :: trace ! ( " " ) ; state . select_down ( ) ; render = true ; } Event :: Done => { selection = state . selection ( ) ; break ; } Event :: Exit => break , _ => ( ) , } ; if render { canvas . render ( & state ) . await ? ; } } log :: trace ! ( " " ) ; Ok ( selection ) }
Run the screen's task
Run the screen ' s task
config
Config
outbound
W
recv
Receiver<Event>