A simple app to choose a random episode of a TV show :)
extern crate cursive;
use cursive::views::{SelectView, TextView, Dialog};
use cursive::align::*;
use cursive::Cursive;
use cursive::traits::*;
use rand::Rng;
fn main() {
let mut app = cursive::default();
let mut select = SelectView::new().h_align(HAlign::Center);
select.add_item("Friends", ("Friends", 10,24));
select.add_item("Seinfeld", ("Seinfeld", 9,23));
select.set_on_submit(|s, (show, seasons, episodes)| {
// s.pop_layer(); - this actually has to be removed, so the selection window can stay 'below' the next one
let (season, episode) = next_episode(*seasons,*episodes);
let text = format!("{}:\n\nwatch episode {} of season {}", show, season, episode);
s.add_layer(Dialog::around(TextView::new(text))
.dismiss_button("Again") //dismisses the window and goes back to the previous layer
.button("Quit", |s| s.quit()));
});
app.add_layer(Dialog::around(select).title("Choose your show:"));
app.run();
}
fn next_episode(seasons: u8, episodes: u8) -> (u8,u8) {
//choose random season and episode number
let season = rand::thread_rng().gen_range(1,seasons + 1);
let episode = rand::thread_rng().gen_range(1,episodes + 1);
return (season, episode);
}