From 6f8a1b75cdffc186f3bf80869cc0e0b5650e0f71 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Fri, 22 Jun 2018 20:49:32 +0530 Subject: View articles complete --- src/main.rs | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9a27b0e..82b0de0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,6 @@ extern crate reqwest; extern crate serde_json; extern crate cursive; -use serde_json::Value; - use cursive::Cursive; use cursive::traits::*; use cursive::views::{TextView, Dialog, EditView, SelectView}; @@ -15,7 +13,6 @@ fn main() { // Initial setup let mut main = Cursive::default(); - main.add_layer(TextView::new("Welcome!")); main.add_global_callback('q', |s| s.quit()); main.add_global_callback('s', |s| search(s)); @@ -26,18 +23,36 @@ fn search(s: &mut Cursive){ fn go(s: &mut Cursive, search: &str) { s.pop_layer(); - let mut result; + let mut result = vec![]; match get_search_results(search) { Ok(x) => result = x, Err(e) => pop_error(s,handler(e)), }; - let choose_result = SelectView::new().with_all_str(result); + 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)); + }); + s.add_layer(Dialog::around(choose_result) + .title("Search Results")); } s.add_layer(Dialog::around(EditView::new() .on_submit(go) .with_id("search") - .fixed_width(10)) + .fixed_size(( 15,2 ))) .title("Search for a page") .button("Go", |s| { let search_txt = s.call_on_id( "search", |v: &mut EditView| { @@ -46,7 +61,24 @@ fn search(s: &mut Cursive){ go(s, &search_txt); }) .button("Cancel", |s| match s.pop_layer(){ - Some(_) => (), - None => (), + _ => () })); } + +// 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))); +// } -- cgit v1.2.3