From db450a92257e19946ca42f01841e7d2990a51976 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Tue, 19 Jun 2018 20:50:28 +0530 Subject: Fix broken imports, add missing import --- src/main.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 6ed1480..bc1188d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,8 @@ extern crate cursive; use serde_json::Value; use cursive::Cursive; -use cursive::{TextView, Dialog, EditView, SelectView}; +use cursive::traits::*; +use cursive::views::{TextView, Dialog, EditView, SelectView}; pub mod content; @@ -13,20 +14,23 @@ fn main() { // Initial setup let mut main = Cursive::default(); - main.add_layer(TextView::new("Welcome!"))); + main.add_layer(TextView::new("Welcome!")); main.add_global_callback('q', |s| s.quit()); - main.add_global_callback('s', search())); + main.add_global_callback('s', |s| search(s)); + + main.run(); } fn search(s: &mut Cursive){ + fn go(s: &mut Cursive, search: &str) { s.pop_layer(); - let search_results: Vec = content::get_search_results(); - let sv = SelectView::with_all_strs(search_results.iter()); + let results = content::get_search_results(search); + s.add_layer(SelectView::new().with_all_str(results)); } s.add_layer(Dialog::around(EditView::new() - .on_submit(render_page()) + .on_submit(go) .with_id("search") .fixed_width(10)) .title("Search for a page") @@ -34,8 +38,10 @@ fn search(s: &mut Cursive){ let search_txt = s.call_on_id( "search", |v: &mut EditView| { v.get_content() }).unwrap(); - - go(s, search_txt); + go(s, &search_txt); }) - .button("Cancel", |s| s.pop_layer())); + .button("Cancel", |s| match s.pop_layer(){ + Some(_) => (), + None => (), + })); } -- cgit v1.2.3