cursive/examples/edit.rs

31 lines
1.2 KiB
Rust
Raw Permalink Normal View History

extern crate cursive;
use cursive::prelude::*;
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()));
}
}));
siv.run();
}