diff options
author | NerdyPepper <[email protected]> | 2018-07-08 17:41:16 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2018-07-08 17:41:16 +0100 |
commit | 2f36286ccc98b1f43c65d9d17e36e99e2553080f (patch) | |
tree | f3c3628a50463e9499d579aa1c787117a80dea50 /src | |
parent | e6ed5a9427e21cf6b113cd8edc6d30409e85c2a3 (diff) |
Start gui for interwiki links
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 36 |
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 | ||
5 | use cursive::Cursive; | 5 | use cursive::Cursive; |
6 | use cursive::traits::*; | 6 | use cursive::traits::*; |
7 | use cursive::views::{ TextView, Dialog, EditView, | 7 | use cursive::views::{ TextView, Dialog, EditView, |
8 | SelectView, OnEventView }; | 8 | SelectView, OnEventView, LinearLayout }; |
9 | 9 | ||
10 | pub mod content; | 10 | pub mod content; |
11 | use content::*; | 11 | use 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 | ||
64 | fn on_submit(s: &mut Cursive, name: &String) { | 67 | fn 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 | } |