sorta done history and going back, but gonna go sleep now, not finished btw
This commit is contained in:
parent
2aa4a82af9
commit
0da9e95b2a
77
src/main.rs
77
src/main.rs
@ -277,35 +277,59 @@ 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(),
|
||||||
|
hostname: "home".to_string(),
|
||||||
|
port: 0,
|
||||||
|
path: "/".to_string(),
|
||||||
|
};
|
||||||
|
if let Ok(parsed_value) = parse_url(user_input, &"example.com".to_string()) {
|
||||||
|
url = parsed_value;
|
||||||
|
history.push(Url {
|
||||||
|
protocol: url.protocol.clone(),
|
||||||
|
hostname: url.hostname.clone(),
|
||||||
|
port: url.port.clone(),
|
||||||
|
path: url.path.clone(),
|
||||||
|
});
|
||||||
'mainloop: loop {
|
'mainloop: loop {
|
||||||
if load_page {
|
if load_page {
|
||||||
history.push(Url {
|
links = Vec::new();
|
||||||
protocol: url.protocol.clone(),
|
links = render_page(history[historical_position].hostname.clone(), history[historical_position].port.clone(), history[historical_position].path.clone());
|
||||||
hostname: url.hostname.clone(),
|
println!("Enter reference number to follow, h for help, or q to quit\n{}",historical_position);
|
||||||
port: url.port.clone(),
|
for i in 0..history.len() {
|
||||||
path: url.path.clone(),
|
println!("{}://{}:{}/{}",history[i].protocol,history[i].hostname, history[i].port, history[i].path);
|
||||||
});
|
}
|
||||||
links = Vec::new();
|
|
||||||
links = render_page(url.hostname.clone(), url.port.clone(), url.path.clone());
|
|
||||||
|
|
||||||
println!("Enter reference number to follow, h for help, or q to quit ");
|
|
||||||
}
|
}
|
||||||
load_page = false;
|
load_page = false;
|
||||||
|
|
||||||
let user_input = input();
|
let user_input = input();
|
||||||
if user_input == "q" {
|
if user_input == "q" {
|
||||||
break 'mainloop;
|
break 'mainloop;
|
||||||
}
|
}
|
||||||
else if user_input == "r" {
|
else if user_input == "r" {
|
||||||
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) {
|
||||||
load_page = true;
|
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;
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user