sorta done history and going back, but gonna go sleep now, not finished btw
This commit is contained in:
		
							
								
								
									
										59
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -277,21 +277,30 @@ fn main() { | |||||||
| 	} | 	} | ||||||
| 	let mut load_page: bool = true; | 	let mut load_page: bool = true; | ||||||
| 	let mut history: Vec<Url> = Vec::new(); | 	let mut history: Vec<Url> = Vec::new(); | ||||||
|  | 	let mut historical_position: usize = 0; | ||||||
| 	let mut links: Vec<String> = Vec::new(); | 	let mut links: Vec<String> = Vec::new(); | ||||||
|  | 	let mut url = Url { | ||||||
| 	if let Ok(url) = parse_url(user_input, &"example.com".to_string()) { | 		protocol: "internal".to_string(), | ||||||
| 		'mainloop: loop { | 		hostname: "home".to_string(), | ||||||
| 			if load_page { | 		port: 0, | ||||||
|  | 		path: "/".to_string(), | ||||||
|  | 	}; | ||||||
|  | 	if let Ok(parsed_value) = parse_url(user_input, &"example.com".to_string()) { | ||||||
|  | 		url = parsed_value; | ||||||
| 		history.push(Url { | 		history.push(Url { | ||||||
| 			protocol: url.protocol.clone(), | 			protocol: url.protocol.clone(), | ||||||
| 			hostname: url.hostname.clone(), | 			hostname: url.hostname.clone(), | ||||||
| 			port: url.port.clone(), | 			port: url.port.clone(), | ||||||
| 			path: url.path.clone(), | 			path: url.path.clone(), | ||||||
| 		});  | 		});  | ||||||
|  | 		'mainloop: loop { | ||||||
|  | 			if load_page { | ||||||
| 				links = Vec::new(); | 				links = Vec::new(); | ||||||
| 			    links = render_page(url.hostname.clone(), url.port.clone(), url.path.clone());    | 				links = render_page(history[historical_position].hostname.clone(), history[historical_position].port.clone(), history[historical_position].path.clone());    | ||||||
|  | 				println!("Enter reference number to follow, h for help, or q to quit\n{}",historical_position); | ||||||
| 			    println!("Enter reference number to follow, h for help, or q to quit "); | 				for i in 0..history.len() { | ||||||
|  | 					println!("{}://{}:{}/{}",history[i].protocol,history[i].hostname, history[i].port, history[i].path); | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 			load_page = false; | 			load_page = false; | ||||||
|  |  | ||||||
| @@ -303,9 +312,24 @@ fn main() { | |||||||
| 				load_page = true; | 				load_page = true; | ||||||
| 				continue; | 				continue; | ||||||
| 			} | 			} | ||||||
|  | 			else if user_input == "i" { | ||||||
|  | 				url.path = "/".to_string(); | ||||||
|  | 				load_page = true; | ||||||
|  | 			} | ||||||
|  | 			else if user_input == "b" { | ||||||
|  | 				if historical_position > 1 { | ||||||
|  | 					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"); | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 			else if user_input == "h" { | 			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 | 				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"); | ||||||
| 			    "); |  | ||||||
| 			} | 			} | ||||||
| 			else if user_input.chars().nth(0).unwrap() == 'o' { | 			else if user_input.chars().nth(0).unwrap() == 'o' { | ||||||
| 			    let number_str = &user_input[1..]; | 			    let number_str = &user_input[1..]; | ||||||
| @@ -317,13 +341,26 @@ fn main() { | |||||||
| 			} | 			} | ||||||
| 			else if let Ok(number) = user_input.parse::<usize>() { | 			else if let Ok(number) = user_input.parse::<usize>() { | ||||||
| 				if number < links.len() { | 				if number < links.len() { | ||||||
| 					let url = parse_url(links[number].clone(), &url.hostname).expect("Error parsing URL"); | 					if let Ok(parsed_value) = parse_url(links[number].clone(), &url.hostname) { | ||||||
|  | 						url = parsed_value; | ||||||
|  | 						history.insert(historical_position+1, Url { | ||||||
|  | 							protocol: url.protocol.clone(), | ||||||
|  | 							hostname: url.hostname.clone(), | ||||||
|  | 							port: url.port.clone(), | ||||||
|  | 							path: url.path.clone(), | ||||||
|  | 						});  | ||||||
|  | 						historical_position += 1; | ||||||
| 						load_page = true; | 						load_page = true; | ||||||
|  | 					} | ||||||
|  | 					else { | ||||||
|  | 						println!("Invalid url"); | ||||||
|  | 					} | ||||||
| 				} else { | 				} else { | ||||||
| 					println!("Invalid reference id"); | 					println!("Invalid reference id"); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			else if let Ok(url) = parse_url(user_input, &url.hostname) { | 			else if let Ok(parsed_value) = parse_url(user_input, &url.hostname) { | ||||||
|  | 				url = parsed_value; | ||||||
| 				load_page = true; | 				load_page = true; | ||||||
| 			} | 			} | ||||||
| 			else { | 			else { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user