From 2f36286ccc98b1f43c65d9d17e36e99e2553080f Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Sun, 8 Jul 2018 22:11:16 +0530 Subject: Start gui for interwiki links --- src/main.rs | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index c59a3f1..ef8dc6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,8 +4,8 @@ extern crate cursive; use cursive::Cursive; use cursive::traits::*; -use cursive::views::{ TextView, Dialog, EditView, - SelectView, OnEventView }; +use cursive::views::{ TextView, Dialog, EditView, + SelectView, OnEventView, LinearLayout }; pub mod content; use content::*; @@ -37,7 +37,10 @@ fn search(s: &mut Cursive){ }; let choose_result = SelectView::::new() .with_all_str(result) - .on_submit(on_submit); + .on_submit(|s, name| { + s.pop_layer(); + on_submit(s, name); + }); s.add_layer(Dialog::around(choose_result) .title("Search Results") .button("Cancel", |s| match s.pop_layer() { _ => () }) @@ -62,28 +65,39 @@ fn search(s: &mut Cursive){ } fn on_submit(s: &mut Cursive, name: &String) { - s.pop_layer(); - // get article data let heading: String = name.clone(); let url = query_url_gen(&name.replace(" ", "_")); - let res = reqwest::get(&url).unwrap(); + let mut res = reqwest::get(&url).unwrap(); let mut extract = String::new(); + let mut link_vec: Vec = vec![]; // handle errors if any - match get_extract(res) { + match get_extract(&mut res) { Ok(x) => extract = x, Err(e) => pop_error(s, handler(e)) }; + match get_links(&mut res) { + Ok(x) => link_vec = x, + Err(e) => pop_error(s, handler(e)) + }; // get the act together let mut article = TextView::new(heading); article.append(String::from("\n\n")); article.append(extract_formatter(extract)); + + let links = SelectView::::new() + .with_all_str(link_vec) + .on_submit(on_submit); s.add_layer( - OnEventView::new( - article.fixed_width(72) - ) - .on_event('t', |s| match s.pop_layer() { _ => () }) + LinearLayout::horizontal() + .child( + OnEventView::new( + article.fixed_width(72) + ) + .on_event('t', |s| match s.pop_layer() { _ => () }) + ) + .child(links) ); } -- cgit v1.2.3