diff options
-rw-r--r-- | src/main.rs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs index 1573cdb..6ed1480 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,23 +1,41 @@ | |||
1 | extern crate reqwest; | 1 | extern crate reqwest; |
2 | extern crate serde_json; | 2 | extern crate serde_json; |
3 | extern crate cursive; | ||
3 | 4 | ||
4 | use serde_json::Value; | 5 | use serde_json::Value; |
5 | 6 | ||
7 | use cursive::Cursive; | ||
8 | use cursive::{TextView, Dialog, EditView, SelectView}; | ||
9 | |||
6 | pub mod content; | 10 | pub mod content; |
7 | 11 | ||
8 | fn main() { | 12 | fn main() { |
9 | let url = format!("https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&list=&meta=&indexpageids=1&continue=%7C%7Cimageinfo&titles={}&exlimit=20&explaintext=1&exsectionformat=plain", title); | 13 | // Initial setup |
10 | let res = reqwest::get(&url); | 14 | let mut main = Cursive::default(); |
11 | 15 | ||
12 | match res { | 16 | main.add_layer(TextView::new("Welcome!"))); |
13 | Ok(res) => { | 17 | main.add_global_callback('q', |s| s.quit()); |
14 | if res.status().is_success() { | 18 | main.add_global_callback('s', search())); |
15 | content::get_extract("") | 19 | } |
16 | } | 20 | |
17 | } | 21 | fn search(s: &mut Cursive){ |
18 | 22 | fn go(s: &mut Cursive, search: &str) { | |
19 | Err(_) { | 23 | s.pop_layer(); |
20 | panic!("Oh no!"); | 24 | let search_results: Vec<String> = content::get_search_results(); |
21 | } | 25 | let sv = SelectView::with_all_strs(search_results.iter()); |
22 | } | 26 | } |
27 | |||
28 | s.add_layer(Dialog::around(EditView::new() | ||
29 | .on_submit(render_page()) | ||
30 | .with_id("search") | ||
31 | .fixed_width(10)) | ||
32 | .title("Search for a page") | ||
33 | .button("Go", |s| { | ||
34 | let search_txt = s.call_on_id( "search", |v: &mut EditView| { | ||
35 | v.get_content() | ||
36 | }).unwrap(); | ||
37 | |||
38 | go(s, search_txt); | ||
39 | }) | ||
40 | .button("Cancel", |s| s.pop_layer())); | ||
23 | } | 41 | } |