2015-05-23 17:33:29 +00:00
|
|
|
extern crate cursive;
|
|
|
|
|
|
|
|
use cursive::Cursive;
|
2015-07-30 12:51:12 +00:00
|
|
|
use cursive::view::{IdView,TextView,Dialog,KeyEventView};
|
2015-05-23 23:46:38 +00:00
|
|
|
|
|
|
|
fn show_popup(siv: &mut Cursive) {
|
|
|
|
|
|
|
|
siv.add_layer(Dialog::new(TextView::new("Tak!"))
|
2015-05-24 00:07:22 +00:00
|
|
|
.button("Change", |s| {
|
2015-05-23 23:46:38 +00:00
|
|
|
// Look for a view tagged "text". We _know_ it's there, so unwrap it.
|
2015-07-30 12:51:12 +00:00
|
|
|
let view = s.find_id::<TextView>("text").unwrap();
|
2015-05-23 23:46:38 +00:00
|
|
|
let content: String = view.get_content().chars().rev().collect();
|
|
|
|
view.set_content(&content);
|
|
|
|
})
|
|
|
|
.dismiss_button("Ok"));
|
|
|
|
|
|
|
|
}
|
2015-05-23 17:33:29 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut siv = Cursive::new();
|
|
|
|
|
2015-05-24 03:28:03 +00:00
|
|
|
let content = "Press Q to quit the application.\n\nPress P to open the popup.";
|
2015-05-23 23:46:38 +00:00
|
|
|
|
2015-05-28 01:04:33 +00:00
|
|
|
siv.add_global_callback('q', |s| s.quit());
|
2015-05-23 22:58:06 +00:00
|
|
|
|
2015-05-23 23:46:38 +00:00
|
|
|
// Let's wrap the view to give it a recognizable ID, so we can look for it.
|
|
|
|
// We add the P callback on the textview only (and not globally),
|
|
|
|
// so that we can't call it when the popup is already visible.
|
|
|
|
siv.add_layer(KeyEventView::new(IdView::new("text", TextView::new(content)))
|
2015-05-28 01:04:33 +00:00
|
|
|
.register('p', |s| show_popup(s)));
|
2015-05-23 23:46:38 +00:00
|
|
|
|
2015-05-23 17:33:29 +00:00
|
|
|
|
|
|
|
siv.run();
|
|
|
|
}
|