4 releases

✓ Uses Rust 2018 edition

new 0.1.3 Sep 9, 2019
0.1.2 Sep 9, 2019
0.1.1 Aug 20, 2019
0.1.0 Aug 20, 2019

#59 in Asynchronous

BSD-3-Clause

210KB
481 lines

Welcome to cursive-async-view 👋

stable build nightly build crates.io Docs.rs GitHub PRs Welcome
A loading-screen wrapper for gyscos/cursive views


This project is work-in-progress

This project provides a wrapper view with a loading screen for gyscos/cursive views. The loading screen will disappear once the wrapped view is fully loaded. This is useful for displaying views which may take long to construct or depend on e.g. the network.

How does it look like? demo terminalizer

Expand to view async-view-loading demo async-view-progress demo

Usage

Simply add to your Cargo.toml

[dependencies]
cursive-async-view = "^0"

Asynchronous view loading without progress information

If you can't tell the progress during a long taking creation of a view, you may wrap the creation of this view in an AsyncView. This will display a loading animation until the inner view is ready to be drawn.

use cursive::{views::TextView, Cursive};
use cursive_async_view::AsyncView;

let mut siv = Cursive::default();
let async_view = AsyncView::new(&siv, move || {
    std::thread::sleep(std::time::Duration::from_secs(10));
    TextView::new("Yay!\n\nThe content has loaded!")
});

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

Asynchronous view loading with a progress bar

If you have information about the progress a long taking view creation has made, you can wrap the creation in an AsyncProgressView. This will display a progress bar until the inner view is ready to be drawn.

use crossbeam::Sender;
use cursive::{views::TextView, Cursive};
use cursive_async_view::AsyncProgressView;

let mut siv = Cursive::default();
let async_view = AsyncProgressView::new(&siv, |s: Sender<f32>| {
    std::thread::sleep(std::time::Duration::from_secs(1));
    s.send(0.2).unwrap();
    std::thread::sleep(std::time::Duration::from_secs(1));
    s.send(0.4).unwrap();
    std::thread::sleep(std::time::Duration::from_secs(1));
    s.send(0.6).unwrap();
    std::thread::sleep(std::time::Duration::from_secs(1));
    s.send(0.8).unwrap();
    std::thread::sleep(std::time::Duration::from_secs(1));
    s.send(1.0).unwrap();
    TextView::new("Yay, the content has loaded!")
});

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

Troubleshooting

If you find any bugs/unexpected behaviour or you have a proposition for future changes open an issue describing the current behaviour and what you expected.

Development cargo test

TBD

Running the tests

Just run

$ cargo test

to execute all available tests.

shields.io endpoints

shields.io endpoints are generated inside the ./target/shields folder. They are used in this README.

Authors

Fin Christensen

:octocat: @fin-ger
🐘 @fin_ger@mastodon.social
🐦 @fin_ger_github


Johannes Wünsche

:octocat: @jwuensche
🐘 @fredowald@mastodon.social
🐦 @Fredowald

Show your support

Give a ⭐️ if this project helped you!

Dependencies

~5MB
~97K SLoC