2015-05-26 22:46:05 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
2016-06-26 00:10:18 +00:00
|
|
|
use cursive::Cursive;
|
|
|
|
use cursive::view::{Dialog, EditView, TextView};
|
2015-05-26 22:46:05 +00:00
|
|
|
|
|
|
|
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.
|
2015-07-28 13:57:52 +00:00
|
|
|
siv.add_layer(Dialog::new(EditView::new().min_length(20).with_id("edit"))
|
2016-06-26 00:10:18 +00:00
|
|
|
.padding((1, 1, 1, 0))
|
|
|
|
.title("Enter your name")
|
|
|
|
.button("Ok", |s| {
|
|
|
|
// When the button is clicked, read the text and print it in a new dialog.
|
|
|
|
let name = s.find_id::<EditView>("edit")
|
|
|
|
.unwrap()
|
|
|
|
.get_content()
|
|
|
|
.to_string();
|
|
|
|
if name.is_empty() {
|
|
|
|
s.add_layer(Dialog::new(TextView::new("Please enter a name!"))
|
|
|
|
.dismiss_button("Ok"));
|
|
|
|
} else {
|
|
|
|
let content = format!("Hello {}!", name);
|
|
|
|
s.pop_layer();
|
|
|
|
s.add_layer(Dialog::new(TextView::new(&content))
|
|
|
|
.button("Quit", |s| s.quit()));
|
|
|
|
}
|
|
|
|
}));
|
2015-05-26 22:46:05 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|