2015-05-26 22:46:05 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
|
|
|
use cursive::{Cursive};
|
|
|
|
use cursive::view::{Dialog,IdView,EditView,Selector,TextView};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut siv = Cursive::new();
|
|
|
|
|
2015-05-26 23:11:22 +00:00
|
|
|
// Create a dialog with an edit text and a button.
|
|
|
|
siv.add_layer(Dialog::new(IdView::new("edit", EditView::new().min_length(20)))
|
2015-05-26 22:46:05 +00:00
|
|
|
.title("Enter your name")
|
|
|
|
.button("Ok", |s| {
|
2015-05-26 23:11:22 +00:00
|
|
|
// When the button is clicked, read the text and print it in a new dialog.
|
2015-05-26 22:46:05 +00:00
|
|
|
let content = {
|
|
|
|
let name = s.find::<EditView>(&Selector::Id("edit")).unwrap().get_content();
|
|
|
|
format!("Hello {}", name)
|
|
|
|
};
|
|
|
|
s.pop_layer();
|
|
|
|
s.add_layer(Dialog::new(TextView::new(&content))
|
|
|
|
.button("Quit", |s| s.quit()));
|
|
|
|
}));
|
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|