cursive/examples/list.rs
Alexandre Bury 969650ab1a Add basic ListView
Show a selection among a list of items.
Maybe should be called SelectView?
TODO:
* Scrolling
* Error handling with empty list
* Action on Enter on an item
2015-05-30 21:05:34 -07:00

26 lines
876 B
Rust

extern crate cursive;
use cursive::Cursive;
use cursive::view::{Dialog,ListView,TextView,Selector};
fn main() {
let mut siv = Cursive::new();
siv.add_layer(Dialog::new(ListView::new()
.item_str("Berlin")
.item_str("London")
.item_str("New York")
.item_str("Paris")
.with_id("city"))
.title("Where are you from?")
.button("Ok", |s| {
let city = s.find::<ListView>(&Selector::Id("city")).unwrap().selection().to_string();
s.pop_layer();
s.add_layer(Dialog::new(TextView::new(&format!("{} is a great city!", city)))
.button("Quit", |s| s.quit()));
}));
siv.run();
}