From 3692828c77246578416d8b1e7642346a6c645393 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Sat, 23 Jun 2018 08:43:23 +0530 Subject: Add basic stack functionality --- src/main.rs | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 82b0de0..d38d474 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,9 @@ 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() { + _ => () + }); main.run(); } @@ -30,21 +33,7 @@ fn search(s: &mut Cursive){ }; let choose_result = SelectView::::new() .with_all_str(result) - .on_submit(|s: &mut Cursive, name: &str| { - s.pop_layer(); - - let url = query_url_gen(&name.replace(" ", "_")); - let res = reqwest::get(&url).unwrap(); - - let mut extract = String::new(); - - match content::get_extract(res) { - Ok(x) => extract = x, - Err(e) => pop_error(s, content::handler(e)) - }; - - s.add_layer(TextView::new(extract)); - }); + .on_submit(on_submit); s.add_layer(Dialog::around(choose_result) .title("Search Results")); } @@ -65,20 +54,20 @@ fn search(s: &mut Cursive){ })); } -// fn on_submit(s: &mut Cursive, name: &String) { -// s.pop_layer(); -// -// let title = name.replace(" ", "_"); -// let url = query_url_gen(&title); -// let res = reqwest::get(&url).unwrap(); -// -// let mut extract = String::new(); -// -// match content::get_extract(res) { -// -// Ok(x) => extract = x, -// Err(e) => pop_error(s, content::handler(e)) -// }; -// -// s.add_layer(Dialog::around(TextView::new(extract))); -// } +fn on_submit(s: &mut Cursive, name: &String) { + s.pop_layer(); + + let title = name.replace(" ", "_"); + let url = query_url_gen(&title); + let res = reqwest::get(&url).unwrap(); + + let mut extract = String::new(); + + match content::get_extract(res) { + + Ok(x) => extract = x, + Err(e) => pop_error(s, content::handler(e)) + }; + + s.add_layer(TextView::new(extract)); +} -- cgit v1.2.3