[][src]Function cursive_async_view::default_progress_error

pub fn default_progress_error(
    msg: String,
    width: usize,
    _height: usize,
    progress: f32,
    pos: usize,
    frame_idx: usize
) -> AnimationProgressFrame

The default error animation for a AsyncProgressView.

Creating your own error animation

The creation is very similar to the progress animation, but the error message is given now as the first parameter.

use crossbeam::Sender;
use cursive::Cursive;
use cursive::views::TextView;
use cursive::utils::markup::StyledString;
use cursive_async_view::{AnimationProgressFrame, AsyncProgressView, AsyncProgressState};

fn my_error_function(
    msg: String,
    _width: usize,
    _height: usize,
    progress: f32,
    _pos: usize,
    frame_idx: usize,
) -> AnimationProgressFrame {
    AnimationProgressFrame {
        content: StyledString::plain(format!("Error: {}", msg)),
        pos: 0,
        next_frame_idx: frame_idx,
    }
}

let mut siv = Cursive::default();
let start = std::time::Instant::now();
let async_view = AsyncProgressView::new(&mut siv, move || {
    if start.elapsed().as_secs() > 5 {
        AsyncProgressState::Pending(start.elapsed().as_secs() as f32 /5f32)
    } else if true {
        AsyncProgressState::Error("Oh no, the view could not be loaded!".to_string())
    } else {
        AsyncProgressState::Available(TextView::new("I thought we never would get here!"))
    }
})
.with_error_fn(my_error_function);