[][src]Function cursive_async_view::default_error

pub fn default_error(
    msg: &str,
    width: usize,
    _height: usize,
    error_idx: usize,
    frame_idx: usize
) -> AnimationFrame

The default error animation for a AsyncView.

Creating your own error function

As an example a very basic error function would look like this:

use std::time::{Instant, Duration};
use cursive::Cursive;
use cursive::views::TextView;
use cursive::utils::markup::StyledString;
use cursive_async_view::{AsyncView, AsyncState, AnimationFrame};

fn my_error_animation(
    msg: &str,
    _width: usize,
    _height: usize,
    _error_idx: usize,
    _frame_idx: usize,
) -> AnimationFrame {
    AnimationFrame {
        content: StyledString::plain(msg),
        next_frame_idx: 0,
    }
}

let mut siv = Cursive::default();
let instant = Instant::now();
let async_view: AsyncView<TextView> = AsyncView::new(&mut siv, move || {
    if instant.elapsed() > Duration::from_secs(5) {
        AsyncState::Error("Oh no, an error occured!".to_string())
    } else {
        AsyncState::Pending
    }
}).with_error_fn(my_error_animation);

siv.add_layer(async_view);
// siv.run();

This error function will just display the error message itself.

The width and height prameters contain the maximum size the content may have (in characters). The initial frame_idx is 0.