2015-05-26 22:46:05 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
2016-09-29 05:45:27 +00:00
|
|
|
use cursive::Cursive;
|
|
|
|
use cursive::traits::*;
|
2017-02-07 02:18:17 +00:00
|
|
|
use cursive::views::{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.
|
2016-07-30 19:58:25 +00:00
|
|
|
// The user can either hit the <Ok> button,
|
|
|
|
// or press Enter on the edit text.
|
2016-10-02 22:15:30 +00:00
|
|
|
siv.add_layer(Dialog::new()
|
2016-07-30 19:58:25 +00:00
|
|
|
.title("Enter your name")
|
|
|
|
.padding((1, 1, 1, 0))
|
|
|
|
.content(EditView::new()
|
|
|
|
.on_submit(show_popup)
|
2016-08-04 04:58:00 +00:00
|
|
|
.with_id("name")
|
|
|
|
.fixed_width(20))
|
2016-07-30 19:58:25 +00:00
|
|
|
.button("Ok", |s| {
|
2017-02-07 02:18:17 +00:00
|
|
|
let name =
|
2017-03-26 01:22:14 +00:00
|
|
|
s.call_on_id("name", |view: &mut EditView| view.get_content())
|
2017-02-07 02:18:17 +00:00
|
|
|
.unwrap();
|
2016-07-30 19:58:25 +00:00
|
|
|
show_popup(s, &name);
|
|
|
|
}));
|
2015-05-26 22:46:05 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|
2016-07-30 19:58:25 +00:00
|
|
|
|
|
|
|
fn show_popup(s: &mut Cursive, name: &str) {
|
|
|
|
if name.is_empty() {
|
|
|
|
s.add_layer(Dialog::info("Please enter a name!"));
|
|
|
|
} else {
|
|
|
|
let content = format!("Hello {}!", name);
|
|
|
|
s.pop_layer();
|
2016-10-02 22:15:30 +00:00
|
|
|
s.add_layer(Dialog::around(TextView::new(content))
|
2016-07-30 19:58:25 +00:00
|
|
|
.button("Quit", |s| s.quit()));
|
|
|
|
}
|
|
|
|
}
|