diff --git a/src/main.rs b/src/main.rs index 60ff349..3e368c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -197,8 +197,6 @@ fn input() -> String{ } fn parse_url(user_input: String, previous_url: &Url) -> Result { - let mut relative = false; - let mut relative_path: &str = "/"; println!("user input: {}",user_input); println!("previous url: {:?}",previous_url); let to_parse = if user_input.contains("://") { @@ -206,7 +204,6 @@ fn parse_url(user_input: String, previous_url: &Url) -> Result user_input } else if user_input[..1] == *"/" { - relative = true; format!("http://{}/{}",Url::host_str(previous_url).expect("ivalid").to_string(), user_input) } else { @@ -217,7 +214,7 @@ fn parse_url(user_input: String, previous_url: &Url) -> Result println!("Parsing: {}", to_parse); if let Ok(mut url) = Url::parse(&to_parse) { if url.port() == None { - url.set_port(Some(3477)); + let _ = url.set_port(Some(3477)); } println!("{:?}",url); println!("{}",url.as_str()); @@ -243,10 +240,10 @@ fn main() { let mut historical_position: usize = 0; let mut links: Vec = Vec::new(); if let Ok(mut url) = parse_url(user_input, &Url::parse(&"http://deadvey.com").unwrap()) { // Change this and make internal pages ;) + history.push(url.clone()); 'mainloop: loop { if load_page { - links = Vec::new(); - links = render_page(url.clone()); + links = render_page(history[historical_position].clone()); println!("Enter reference number to follow, h for help, or q to quit"); } load_page = false; @@ -258,23 +255,25 @@ fn main() { else if user_input == "r" { load_page = true; continue; - }/* - else if user_input == "i" { - url.path = "/".to_string(); - load_page = true; } else if user_input == "b" { - if historical_position >= 1 { + if historical_position > 0 { historical_position -= 1; - if let Ok(parsed_value) = parse_url(format!("{}://{}/{}",history[historical_position].protocol.clone(), history[historical_position].hostname.clone(),history[historical_position].path.clone()),&url.hostname) { - url = parsed_value; - load_page = true; - } - else { - println!("Invalid url"); - } + load_page = true; } - }*/ + else { + println!("At start of history"); + } + } + else if user_input == "f" { + if historical_position < history.len()-1 { + historical_position += 1; + load_page = true; + } + else { + println!("At end of history"); + } + } else if user_input == "h" { println!("Source code: https://git.javalsai.dynv6.net/deadvey/markdown-webbrowser\nq: quit\nh: help\nr: reload\ni: visit root index of this host eg: root index of mttp://deadvey.com/blog/4.md is just deadvey.com\nb: go back in history\nox: print the hyprlink of reference x eg: o5 or o24"); } @@ -288,13 +287,13 @@ fn main() { } else if let Ok(number) = user_input.parse::() { if number < links.len() { - if let Ok(parsed_value) = parse_url(links[number].clone(), &url) { + if let Ok(parsed_value) = parse_url(links[number].clone(), &url.clone()) { url = parsed_value; - /* - for i in historical_position+1..history.len()-1 { - history.remove(i); + for _i in historical_position+1..history.len() { + history.remove(historical_position+1); } - historical_position += 1;*/ + history.push(url.clone()); + historical_position += 1; load_page = true; } else {