2016-07-25 06:00:13 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
|
|
|
use cursive::prelude::*;
|
|
|
|
|
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut siv = Cursive::new();
|
|
|
|
|
2016-07-26 03:43:01 +00:00
|
|
|
siv.add_layer(Dialog::empty()
|
|
|
|
.title("Progress bar example")
|
|
|
|
.padding((0, 0, 1, 1))
|
|
|
|
.content(Button::new("Start", |s| {
|
2016-07-26 19:10:13 +00:00
|
|
|
// Number of ticks
|
2016-07-26 06:54:33 +00:00
|
|
|
let n_max = 1000;
|
2016-07-25 06:00:13 +00:00
|
|
|
|
2016-07-26 19:10:13 +00:00
|
|
|
// This is the callback channel
|
2016-07-26 17:13:36 +00:00
|
|
|
let cb = s.cb_sink().clone();
|
2016-07-25 06:00:13 +00:00
|
|
|
|
2016-07-26 19:10:13 +00:00
|
|
|
s.pop_layer();
|
|
|
|
s.add_layer(Panel::new(FullView::full_width(
|
|
|
|
ProgressBar::new()
|
|
|
|
.range(0, n_max)
|
|
|
|
.with_task(move |ticker| {
|
|
|
|
// This closure will be called in a separate thread.
|
|
|
|
for _ in 0..n_max {
|
|
|
|
thread::sleep(Duration::from_millis(5));
|
|
|
|
// The ticker method increases the progress value
|
|
|
|
ticker(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When we're done, send a callback through the channel
|
|
|
|
cb.send(Box::new(move |s| {
|
|
|
|
s.pop_layer();
|
|
|
|
s.add_layer(Dialog::empty()
|
|
|
|
.title("Work done!")
|
|
|
|
.content(TextView::new("Phew!"))
|
|
|
|
.button("Finally!", |s| s.quit()));
|
|
|
|
}))
|
|
|
|
.unwrap();
|
|
|
|
})
|
|
|
|
)));
|
|
|
|
})));
|
2016-07-25 06:00:13 +00:00
|
|
|
|
2016-07-25 20:35:46 +00:00
|
|
|
siv.set_fps(30);
|
2016-07-25 06:00:13 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|