aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index e604b40..1688ddc 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,6 +10,8 @@ use cursive::views::{
10 DummyView 10 DummyView
11}; 11};
12 12
13use serde_json::Value;
14
13pub mod content; 15pub mod content;
14use content::*; 16use content::*;
15 17
@@ -23,6 +25,7 @@ fn main() {
23 // set theme 25 // set theme
24 main.set_theme(theme_gen()); 26 main.set_theme(theme_gen());
25 27
28
26 main.add_global_callback('q', |s| s.quit()); 29 main.add_global_callback('q', |s| s.quit());
27 main.add_global_callback('s', |s| search(s)); 30 main.add_global_callback('s', |s| search(s));
28 31
@@ -74,14 +77,17 @@ fn on_submit(s: &mut Cursive, name: &String) {
74 let mut extract = String::new(); 77 let mut extract = String::new();
75 let mut link_vec: Vec<String> = vec![]; 78 let mut link_vec: Vec<String> = vec![];
76 79
77 // handle errors if any 80 let mut res = reqwest::get(&url).unwrap();
78 let res = reqwest::get(&url).unwrap(); 81 let v: Value = match serde_json::from_str(&res.text().unwrap()) {
79 match get_extract(res) { 82 Ok(x) => x,
83 Err(x) => panic!("Failed to parse json\nReceived error {}", x),
84 };
85
86 match get_extract(&v) {
80 Ok(x) => extract = x, 87 Ok(x) => extract = x,
81 Err(e) => pop_error(s, handler(e)) 88 Err(e) => pop_error(s, handler(e))
82 }; 89 };
83 let res = reqwest::get(&url).unwrap(); 90 match get_links(&v) {
84 match get_links(res) {
85 Ok(x) => link_vec = x, 91 Ok(x) => link_vec = x,
86 Err(e) => pop_error(s, handler(e)) 92 Err(e) => pop_error(s, handler(e))
87 }; 93 };