extern crate cursive;
use cursive::Cursive;
use cursive::view::{Boxable, Identifiable};
use cursive::views::{Dialog, EditView, LinearLayout, TextView};
fn main() {
let mut siv = Cursive::new();
siv.add_layer(
Dialog::around(
LinearLayout::vertical()
.child(EditView::new().on_edit(on_edit).with_id("1"))
.child(EditView::new().on_edit(on_edit).with_id("2"))
.child(TextView::new("match").with_id("match"))
.fixed_width(10),
).button("Quit", Cursive::quit),
);
siv.run();
}
fn on_edit(siv: &mut Cursive, _content: &str, _cursor: usize) {
let edit_1 = siv.find_id::<EditView>("1").unwrap();
let edit_2 = siv.find_id::<EditView>("2").unwrap();
let matches = edit_1.get_content() == edit_2.get_content();
siv.call_on_id("match", |v: &mut TextView| {
v.set_content(if matches { "match" } else { "no match" })
});
}