diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/content.rs | 5 | ||||
-rw-r--r-- | src/main.rs | 51 |
2 files changed, 50 insertions, 6 deletions
diff --git a/src/content.rs b/src/content.rs index 8d025c9..a192446 100644 --- a/src/content.rs +++ b/src/content.rs | |||
@@ -10,10 +10,11 @@ use cursive::Cursive; | |||
10 | use cursive::views::Dialog; | 10 | use cursive::views::Dialog; |
11 | use serde_json::Value; | 11 | use serde_json::Value; |
12 | use self::regex::Regex; | 12 | use self::regex::Regex; |
13 | use CONFIGURATION; | ||
13 | 14 | ||
14 | pub fn query_url_gen(title: &str) -> String { | 15 | pub fn query_url_gen(title: &str) -> String { |
15 | // query config | 16 | // query config |
16 | let mut url = String::from("https://en.wikipedia.org"); | 17 | let mut url = CONFIGURATION.wiki_url.clone(); |
17 | url.push_str("/w/api.php?"); | 18 | url.push_str("/w/api.php?"); |
18 | url.push_str("action=query&"); | 19 | url.push_str("action=query&"); |
19 | url.push_str("format=json&"); | 20 | url.push_str("format=json&"); |
@@ -31,7 +32,7 @@ pub fn query_url_gen(title: &str) -> String { | |||
31 | pub fn search_url_gen(search: &str) -> String { | 32 | pub fn search_url_gen(search: &str) -> String { |
32 | // search config | 33 | // search config |
33 | let search = search.replace(" ", "%20"); | 34 | let search = search.replace(" ", "%20"); |
34 | let mut url = String::from("https://en.wikipedia.org"); | 35 | let mut url = CONFIGURATION.wiki_url.clone(); |
35 | url.push_str("/w/api.php?"); | 36 | url.push_str("/w/api.php?"); |
36 | url.push_str("action=opensearch&"); | 37 | url.push_str("action=opensearch&"); |
37 | url.push_str("format=json&"); | 38 | url.push_str("format=json&"); |
diff --git a/src/main.rs b/src/main.rs index 0dbed8f..ff87931 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,6 +1,9 @@ | |||
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 clap; | ||
5 | #[macro_use] | ||
6 | extern crate lazy_static; | ||
4 | 7 | ||
5 | use cursive::Cursive; | 8 | use cursive::Cursive; |
6 | use cursive::traits::*; | 9 | use cursive::traits::*; |
@@ -12,17 +15,29 @@ use cursive::views::{ | |||
12 | 15 | ||
13 | use serde_json::Value; | 16 | use serde_json::Value; |
14 | 17 | ||
18 | use clap::{Arg, App}; | ||
19 | |||
15 | pub mod content; | 20 | pub mod content; |
16 | use content::*; | 21 | use content::*; |
17 | 22 | ||
18 | pub mod theme; | 23 | pub mod theme; |
19 | use theme::*; | 24 | use theme::*; |
20 | 25 | ||
26 | struct Configuration { | ||
27 | wiki_url: String | ||
28 | } | ||
29 | |||
30 | lazy_static! { | ||
31 | static ref CONFIGURATION: Configuration = parse_arguments(); | ||
32 | } | ||
33 | |||
21 | fn main() { | 34 | fn main() { |
35 | parse_arguments(); | ||
36 | |||
22 | // Initial setup | 37 | // Initial setup |
23 | let mut main = Cursive::default(); | 38 | let mut main = Cursive::default(); |
24 | 39 | ||
25 | // set theme | 40 | // Set theme |
26 | main.set_theme(theme_gen()); | 41 | main.set_theme(theme_gen()); |
27 | 42 | ||
28 | 43 | ||
@@ -32,7 +47,35 @@ fn main() { | |||
32 | main.run(); | 47 | main.run(); |
33 | } | 48 | } |
34 | 49 | ||
35 | fn search(s: &mut Cursive){ | 50 | fn parse_arguments() -> Configuration { |
51 | let matches = App::new("Taizen") | ||
52 | .version("0.1.0") | ||
53 | .author("NerdyPepper") | ||
54 | .about("TUI MediaWiki browser") | ||
55 | .arg(Arg::with_name("URL") | ||
56 | .help("The URL of the wiki to be viewed") | ||
57 | .index(1)) | ||
58 | .arg(Arg::with_name("lang") | ||
59 | .short("l") | ||
60 | .long("lang") | ||
61 | .value_name("CODE") | ||
62 | .help("Choose the language for Wikipedia") | ||
63 | .takes_value(true)) | ||
64 | .get_matches(); | ||
65 | |||
66 | if matches.is_present("HELP") { | ||
67 | std::process::exit(0); | ||
68 | } | ||
69 | |||
70 | let lang = matches.value_of("lang").unwrap_or("en").to_string(); | ||
71 | let wiki_url = matches.value_of("URL").unwrap_or(&format!("https://{}.wikipedia.org", lang)).to_string(); | ||
72 | |||
73 | Configuration { | ||
74 | wiki_url | ||
75 | } | ||
76 | } | ||
77 | |||
78 | fn search(s: &mut Cursive) { | ||
36 | 79 | ||
37 | fn go(s: &mut Cursive, search: &str) { | 80 | fn go(s: &mut Cursive, search: &str) { |
38 | s.pop_layer(); | 81 | s.pop_layer(); |
@@ -70,9 +113,9 @@ fn search(s: &mut Cursive){ | |||
70 | .fixed_size(( 35, 5 ))); | 113 | .fixed_size(( 35, 5 ))); |
71 | } | 114 | } |
72 | 115 | ||
73 | fn on_submit(s: &mut Cursive, name: &String) { | 116 | fn on_submit(s: &mut Cursive, name: &str) { |
74 | // get article data | 117 | // get article data |
75 | let heading: String = name.clone(); | 118 | let heading: String = name.to_string(); |
76 | let url = query_url_gen(&name.replace(" ", "_")); | 119 | let url = query_url_gen(&name.replace(" ", "_")); |
77 | let mut extract = String::new(); | 120 | let mut extract = String::new(); |
78 | let mut link_vec: Vec<String> = vec![]; | 121 | let mut link_vec: Vec<String> = vec![]; |