aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs51
1 files changed, 47 insertions, 4 deletions
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 @@
1extern crate reqwest; 1extern crate reqwest;
2extern crate serde_json; 2extern crate serde_json;
3extern crate cursive; 3extern crate cursive;
4extern crate clap;
5#[macro_use]
6extern crate lazy_static;
4 7
5use cursive::Cursive; 8use cursive::Cursive;
6use cursive::traits::*; 9use cursive::traits::*;
@@ -12,17 +15,29 @@ use cursive::views::{
12 15
13use serde_json::Value; 16use serde_json::Value;
14 17
18use clap::{Arg, App};
19
15pub mod content; 20pub mod content;
16use content::*; 21use content::*;
17 22
18pub mod theme; 23pub mod theme;
19use theme::*; 24use theme::*;
20 25
26struct Configuration {
27 wiki_url: String
28}
29
30lazy_static! {
31 static ref CONFIGURATION: Configuration = parse_arguments();
32}
33
21fn main() { 34fn 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
35fn search(s: &mut Cursive){ 50fn 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
78fn 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
73fn on_submit(s: &mut Cursive, name: &String) { 116fn 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![];