From a5bf6b5555c42a47e4d8892748fe4452977396fd Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Thu, 28 Jun 2018 12:59:26 +0530 Subject: Move from global callbacks to events --- src/main.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index ad62b77..9add0c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,8 @@ extern crate serde_json; extern crate cursive; use cursive::Cursive; -use cursive::align::HAlign; use cursive::traits::*; -use cursive::views::{ TextView, Dialog, EditView, SelectView, LinearLayout, DummyView }; +use cursive::views::{ TextView, Dialog, EditView, SelectView, OnEventView }; pub mod content; use content::*; @@ -16,11 +15,6 @@ fn main() { main.add_global_callback('q', |s| s.quit()); main.add_global_callback('s', |s| search(s)); - main.add_global_callback('t', |s| match s.pop_layer() { - Some(_) => (), - None => s.add_layer( Dialog::text("Stack is empty!") - .title("Error") - )}); main.run(); } @@ -38,13 +32,14 @@ fn search(s: &mut Cursive){ .with_all_str(result) .on_submit(on_submit); s.add_layer(Dialog::around(choose_result) - .title("Search Results")); + .title("Search Results") + .fixed_size(( 45,8 ))); } s.add_layer(Dialog::around(EditView::new() .on_submit(go) .with_id("search") - .fixed_size(( 15,2 ))) + ) .title("Search for a page") .button("Go", |s| { let search_txt = s.call_on_id( "search", |v: &mut EditView| { @@ -72,10 +67,13 @@ fn on_submit(s: &mut Cursive, name: &String) { }; s.add_layer( - Dialog::around(TextView::new(extract)) + Dialog::around( + OnEventView::new(TextView::new(extract)) + .on_event('t', |s| match s.pop_layer() { _ => () }) + ) .title(heading) - .padding_right(5) - .padding_left(5) + .padding_right(2) + .padding_left(2) .max_width(80) ); } -- cgit v1.2.3