2015-05-31 04:05:34 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
2015-05-31 23:38:53 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{BufReader,BufRead};
|
|
|
|
|
2015-05-31 04:05:34 +00:00
|
|
|
use cursive::Cursive;
|
2015-05-31 23:38:53 +00:00
|
|
|
use cursive::view::{Dialog,SelectView,TextView,Selector,BoxView};
|
2015-05-31 04:05:34 +00:00
|
|
|
|
|
|
|
fn main() {
|
2015-05-31 23:58:55 +00:00
|
|
|
// To keep things simple, little error management is done here.
|
|
|
|
// If you have an error, be sure to run this from the crate root, not from a sub directory.
|
2015-05-31 23:38:53 +00:00
|
|
|
|
|
|
|
let mut select = SelectView::new();
|
|
|
|
|
|
|
|
// Read the list of cities from separate file, and fill the view with it.
|
|
|
|
let file = File::open("assets/cities.txt").unwrap();
|
|
|
|
let reader = BufReader::new(file);
|
|
|
|
for line in reader.lines() {
|
|
|
|
select.add_item_str(&line.unwrap());
|
|
|
|
}
|
|
|
|
|
2015-05-31 04:05:34 +00:00
|
|
|
let mut siv = Cursive::new();
|
|
|
|
|
2015-05-31 23:58:55 +00:00
|
|
|
// Let's add a BoxView to keep the list at a reasonable size - it can scroll anyway.
|
2015-05-31 23:38:53 +00:00
|
|
|
siv.add_layer(Dialog::new(BoxView::new((20,10), select.with_id("city")))
|
2015-05-31 04:05:34 +00:00
|
|
|
.title("Where are you from?")
|
|
|
|
.button("Ok", |s| {
|
2015-05-31 23:58:55 +00:00
|
|
|
// Find the SelectView, gets its selection.
|
2015-05-31 04:32:24 +00:00
|
|
|
let city = s.find::<SelectView>(&Selector::Id("city")).unwrap().selection().to_string();
|
2015-05-31 23:58:55 +00:00
|
|
|
// And show the next window.
|
2015-05-31 04:05:34 +00:00
|
|
|
s.pop_layer();
|
|
|
|
s.add_layer(Dialog::new(TextView::new(&format!("{} is a great city!", city)))
|
|
|
|
.button("Quit", |s| s.quit()));
|
|
|
|
}));
|
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|
|
|
|
|