diff options
-rw-r--r-- | src/content.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/content.rs b/src/content.rs index 585f6b2..e31531b 100644 --- a/src/content.rs +++ b/src/content.rs | |||
@@ -1,11 +1,15 @@ | |||
1 | extern crate reqwest; | 1 | extern crate reqwest; |
2 | extern crate serde_json; | 2 | extern crate serde_json; |
3 | extern crate cursive; | 3 | extern crate cursive; |
4 | extern crate regex; | ||
4 | 5 | ||
6 | use cursive::theme::{ BaseColor, Color, Effect, Style }; | ||
7 | use cursive::utils::markup::StyledString; | ||
5 | use cursive::Cursive; | 8 | use cursive::Cursive; |
6 | use cursive::views::Dialog; | 9 | use cursive::views::Dialog; |
7 | use serde_json::Value; | 10 | use serde_json::Value; |
8 | use reqwest::Response; | 11 | use reqwest::Response; |
12 | use self::regex::Regex; | ||
9 | 13 | ||
10 | pub fn query_url_gen(title: &str) -> String { | 14 | pub fn query_url_gen(title: &str) -> String { |
11 | // query config | 15 | // query config |
@@ -61,6 +65,33 @@ pub fn get_extract(mut res: Response) -> Result<String, reqwest::Error> { | |||
61 | } | 65 | } |
62 | } | 66 | } |
63 | 67 | ||
68 | pub fn extract_formatter(extract: String) -> StyledString { | ||
69 | let mut formatted = StyledString::new(); | ||
70 | |||
71 | let heading= Regex::new(r"^== (?P<d>.*) ==$").unwrap(); | ||
72 | let subheading= Regex::new(r"^=== (?P<d>.*) ===$").unwrap(); | ||
73 | |||
74 | for line in extract.lines() { | ||
75 | if heading.is_match(line) { | ||
76 | formatted.append( | ||
77 | StyledString::styled( | ||
78 | heading.replace(line, "$d"), Effect::Bold | ||
79 | ) | ||
80 | ); | ||
81 | } else if subheading.is_match(line) { | ||
82 | formatted.append( | ||
83 | StyledString::styled( | ||
84 | subheading.replace(line, "$d"), Effect::Italic | ||
85 | ) | ||
86 | ); | ||
87 | } else { | ||
88 | formatted.append(StyledString::plain(line)); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | formatted | ||
93 | } | ||
94 | |||
64 | pub fn get_search_results(search: &str) -> Result<Vec<String>, reqwest::Error> { | 95 | pub fn get_search_results(search: &str) -> Result<Vec<String>, reqwest::Error> { |
65 | let url = search_url_gen(search); | 96 | let url = search_url_gen(search); |
66 | let mut res = reqwest::get(&url[..])?; | 97 | let mut res = reqwest::get(&url[..])?; |