2015-05-31 04:05:34 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
2015-05-31 23:38:53 +00:00
|
|
|
use std::fs::File;
|
2016-06-26 00:10:18 +00:00
|
|
|
use std::io::{BufReader, BufRead};
|
2015-05-31 23:38:53 +00:00
|
|
|
|
2015-05-31 04:05:34 +00:00
|
|
|
use cursive::Cursive;
|
2015-06-02 21:23:51 +00:00
|
|
|
use cursive::align::HAlign;
|
2016-06-26 00:10:18 +00:00
|
|
|
use cursive::view::{Dialog, SelectView, TextView, 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
|
|
|
|
2015-06-02 21:23:51 +00:00
|
|
|
let mut select = SelectView::new().h_align(HAlign::Center);
|
2015-05-31 23:38:53 +00:00
|
|
|
|
|
|
|
// 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-07-28 19:54:32 +00:00
|
|
|
select.set_on_select(show_next_window);
|
2015-05-31 23:38:53 +00:00
|
|
|
|
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.
|
2016-07-12 02:24:00 +00:00
|
|
|
siv.add_layer(Dialog::new(BoxView::fixed_size((20, 10), select))
|
2016-06-26 00:10:18 +00:00
|
|
|
.title("Where are you from?"));
|
2015-05-31 04:05:34 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|
|
|
|
|
2015-06-01 03:47:04 +00:00
|
|
|
// Let's put the callback in a separate function to keep it clean, but it's not required.
|
2015-07-28 19:54:32 +00:00
|
|
|
fn show_next_window(siv: &mut Cursive, city: &String) {
|
2015-06-01 03:47:04 +00:00
|
|
|
siv.pop_layer();
|
|
|
|
siv.add_layer(Dialog::new(TextView::new(&format!("{} is a great city!", city)))
|
2016-06-26 00:10:18 +00:00
|
|
|
.button("Quit", |s| s.quit()));
|
2015-06-01 03:47:04 +00:00
|
|
|
}
|