aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2018-07-08 17:41:16 +0100
committerNerdyPepper <[email protected]>2018-07-08 17:41:16 +0100
commit2f36286ccc98b1f43c65d9d17e36e99e2553080f (patch)
treef3c3628a50463e9499d579aa1c787117a80dea50 /src
parente6ed5a9427e21cf6b113cd8edc6d30409e85c2a3 (diff)
Start gui for interwiki links
Diffstat (limited to 'src')
-rw-r--r--src/main.rs36
1 files changed, 25 insertions, 11 deletions
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;
4 4
5use cursive::Cursive; 5use cursive::Cursive;
6use cursive::traits::*; 6use cursive::traits::*;
7use cursive::views::{ TextView, Dialog, EditView, 7use cursive::views::{ TextView, Dialog, EditView,
8 SelectView, OnEventView }; 8 SelectView, OnEventView, LinearLayout };
9 9
10pub mod content; 10pub mod content;
11use content::*; 11use content::*;
@@ -37,7 +37,10 @@ fn search(s: &mut Cursive){
37 }; 37 };
38 let choose_result = SelectView::<String>::new() 38 let choose_result = SelectView::<String>::new()
39 .with_all_str(result) 39 .with_all_str(result)
40 .on_submit(on_submit); 40 .on_submit(|s, name| {
41 s.pop_layer();
42 on_submit(s, name);
43 });
41 s.add_layer(Dialog::around(choose_result) 44 s.add_layer(Dialog::around(choose_result)
42 .title("Search Results") 45 .title("Search Results")
43 .button("Cancel", |s| match s.pop_layer() { _ => () }) 46 .button("Cancel", |s| match s.pop_layer() { _ => () })
@@ -62,28 +65,39 @@ fn search(s: &mut Cursive){
62} 65}
63 66
64fn on_submit(s: &mut Cursive, name: &String) { 67fn on_submit(s: &mut Cursive, name: &String) {
65 s.pop_layer();
66
67 // get article data 68 // get article data
68 let heading: String = name.clone(); 69 let heading: String = name.clone();
69 let url = query_url_gen(&name.replace(" ", "_")); 70 let url = query_url_gen(&name.replace(" ", "_"));
70 let res = reqwest::get(&url).unwrap(); 71 let mut res = reqwest::get(&url).unwrap();
71 let mut extract = String::new(); 72 let mut extract = String::new();
73 let mut link_vec: Vec<String> = vec![];
72 74
73 // handle errors if any 75 // handle errors if any
74 match get_extract(res) { 76 match get_extract(&mut res) {
75 Ok(x) => extract = x, 77 Ok(x) => extract = x,
76 Err(e) => pop_error(s, handler(e)) 78 Err(e) => pop_error(s, handler(e))
77 }; 79 };
80 match get_links(&mut res) {
81 Ok(x) => link_vec = x,
82 Err(e) => pop_error(s, handler(e))
83 };
78 84
79 // get the act together 85 // get the act together
80 let mut article = TextView::new(heading); 86 let mut article = TextView::new(heading);
81 article.append(String::from("\n\n")); 87 article.append(String::from("\n\n"));
82 article.append(extract_formatter(extract)); 88 article.append(extract_formatter(extract));
89
90 let links = SelectView::<String>::new()
91 .with_all_str(link_vec)
92 .on_submit(on_submit);
83 s.add_layer( 93 s.add_layer(
84 OnEventView::new( 94 LinearLayout::horizontal()
85 article.fixed_width(72) 95 .child(
86 ) 96 OnEventView::new(
87 .on_event('t', |s| match s.pop_layer() { _ => () }) 97 article.fixed_width(72)
98 )
99 .on_event('t', |s| match s.pop_layer() { _ => () })
100 )
101 .child(links)
88 ); 102 );
89} 103}