diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 48 |
1 files 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; | |||
2 | extern crate serde_json; | 2 | extern crate serde_json; |
3 | extern crate cursive; | 3 | extern crate cursive; |
4 | 4 | ||
5 | use serde_json::Value; | ||
6 | |||
7 | use cursive::Cursive; | 5 | use cursive::Cursive; |
8 | use cursive::traits::*; | 6 | use cursive::traits::*; |
9 | use cursive::views::{TextView, Dialog, EditView, SelectView}; | 7 | use cursive::views::{TextView, Dialog, EditView, SelectView}; |
@@ -15,7 +13,6 @@ fn main() { | |||
15 | // Initial setup | 13 | // Initial setup |
16 | let mut main = Cursive::default(); | 14 | let mut main = Cursive::default(); |
17 | 15 | ||
18 | main.add_layer(TextView::new("Welcome!")); | ||
19 | main.add_global_callback('q', |s| s.quit()); | 16 | main.add_global_callback('q', |s| s.quit()); |
20 | main.add_global_callback('s', |s| search(s)); | 17 | main.add_global_callback('s', |s| search(s)); |
21 | 18 | ||
@@ -26,18 +23,36 @@ fn search(s: &mut Cursive){ | |||
26 | 23 | ||
27 | fn go(s: &mut Cursive, search: &str) { | 24 | fn go(s: &mut Cursive, search: &str) { |
28 | s.pop_layer(); | 25 | s.pop_layer(); |
29 | let mut result; | 26 | let mut result = vec![]; |
30 | match get_search_results(search) { | 27 | match get_search_results(search) { |
31 | Ok(x) => result = x, | 28 | Ok(x) => result = x, |
32 | Err(e) => pop_error(s,handler(e)), | 29 | Err(e) => pop_error(s,handler(e)), |
33 | }; | 30 | }; |
34 | let choose_result = SelectView::new().with_all_str(result); | 31 | let choose_result = SelectView::<String>::new() |
32 | .with_all_str(result) | ||
33 | .on_submit(|s: &mut Cursive, name: &str| { | ||
34 | s.pop_layer(); | ||
35 | |||
36 | let url = query_url_gen(&name.replace(" ", "_")); | ||
37 | let res = reqwest::get(&url).unwrap(); | ||
38 | |||
39 | let mut extract = String::new(); | ||
40 | |||
41 | match content::get_extract(res) { | ||
42 | Ok(x) => extract = x, | ||
43 | Err(e) => pop_error(s, content::handler(e)) | ||
44 | }; | ||
45 | |||
46 | s.add_layer(TextView::new(extract)); | ||
47 | }); | ||
48 | s.add_layer(Dialog::around(choose_result) | ||
49 | .title("Search Results")); | ||
35 | } | 50 | } |
36 | 51 | ||
37 | s.add_layer(Dialog::around(EditView::new() | 52 | s.add_layer(Dialog::around(EditView::new() |
38 | .on_submit(go) | 53 | .on_submit(go) |
39 | .with_id("search") | 54 | .with_id("search") |
40 | .fixed_width(10)) | 55 | .fixed_size(( 15,2 ))) |
41 | .title("Search for a page") | 56 | .title("Search for a page") |
42 | .button("Go", |s| { | 57 | .button("Go", |s| { |
43 | let search_txt = s.call_on_id( "search", |v: &mut EditView| { | 58 | let search_txt = s.call_on_id( "search", |v: &mut EditView| { |
@@ -46,7 +61,24 @@ fn search(s: &mut Cursive){ | |||
46 | go(s, &search_txt); | 61 | go(s, &search_txt); |
47 | }) | 62 | }) |
48 | .button("Cancel", |s| match s.pop_layer(){ | 63 | .button("Cancel", |s| match s.pop_layer(){ |
49 | Some(_) => (), | 64 | _ => () |
50 | None => (), | ||
51 | })); | 65 | })); |
52 | } | 66 | } |
67 | |||
68 | // fn on_submit(s: &mut Cursive, name: &String) { | ||
69 | // s.pop_layer(); | ||
70 | // | ||
71 | // let title = name.replace(" ", "_"); | ||
72 | // let url = query_url_gen(&title); | ||
73 | // let res = reqwest::get(&url).unwrap(); | ||
74 | // | ||
75 | // let mut extract = String::new(); | ||
76 | // | ||
77 | // match content::get_extract(res) { | ||
78 | // | ||
79 | // Ok(x) => extract = x, | ||
80 | // Err(e) => pop_error(s, content::handler(e)) | ||
81 | // }; | ||
82 | // | ||
83 | // s.add_layer(Dialog::around(TextView::new(extract))); | ||
84 | // } | ||