source code viewing
This commit is contained in:
parent
7b9d2d6fd3
commit
5f856f35fe
34
src/main.rs
34
src/main.rs
@ -153,13 +153,16 @@ fn fetch_page(url: &Url) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_page(url: Url) -> Vec<String> {
|
fn render_page(url: Url, source: bool) -> Vec<String> {
|
||||||
clear_screen();
|
clear_screen();
|
||||||
let mut content = fetch_page(&url);
|
let mut content = fetch_page(&url);
|
||||||
let mut links = Vec::new();
|
let mut links = Vec::new();
|
||||||
let (screen_width, _screen_height) = termion::terminal_size().unwrap();
|
let (screen_width, _screen_height) = termion::terminal_size().unwrap();
|
||||||
|
|
||||||
if &content[..13] == "<!DOCTYPE md>" {
|
if source == true {
|
||||||
|
content += &format!("{}", &"Viewing source code".yellow());
|
||||||
|
}
|
||||||
|
else if &content[..13] == "<!DOCTYPE md>" {
|
||||||
(content, links) = parse_markdown((&content[13..]).to_string());
|
(content, links) = parse_markdown((&content[13..]).to_string());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -239,11 +242,12 @@ fn main() {
|
|||||||
let mut history: Vec<Url> = Vec::new();
|
let mut history: Vec<Url> = Vec::new();
|
||||||
let mut historical_position: usize = 0;
|
let mut historical_position: usize = 0;
|
||||||
let mut links: Vec<String> = Vec::new();
|
let mut links: Vec<String> = Vec::new();
|
||||||
|
let mut source: bool = false; // Wether to view source of markdown page or rendered version
|
||||||
if let Ok(mut url) = parse_url(user_input, &Url::parse(&"http://deadvey.com").unwrap()) { // Change this and make internal pages ;)
|
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());
|
history.push(url.clone());
|
||||||
'mainloop: loop {
|
'mainloop: loop {
|
||||||
if load_page {
|
if load_page {
|
||||||
links = render_page(history[historical_position].clone());
|
links = render_page(history[historical_position].clone(), source);
|
||||||
println!("Enter reference number to follow, h for help, or q to quit");
|
println!("Enter reference number to follow, h for help, or q to quit");
|
||||||
}
|
}
|
||||||
load_page = false;
|
load_page = false;
|
||||||
@ -256,6 +260,19 @@ fn main() {
|
|||||||
load_page = true;
|
load_page = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
else if user_input == "s" {
|
||||||
|
source = ! source; // Flip the boolean to toggle source mode
|
||||||
|
load_page = true;
|
||||||
|
}
|
||||||
|
else if user_input == "i" {
|
||||||
|
let _ = url.set_path("/");
|
||||||
|
for _i in historical_position+1..history.len() {
|
||||||
|
history.remove(historical_position+1);
|
||||||
|
}
|
||||||
|
history.push(url.clone());
|
||||||
|
historical_position += 1;
|
||||||
|
load_page = true;
|
||||||
|
}
|
||||||
else if user_input == "b" {
|
else if user_input == "b" {
|
||||||
if historical_position > 0 {
|
if historical_position > 0 {
|
||||||
historical_position -= 1;
|
historical_position -= 1;
|
||||||
@ -275,7 +292,16 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
||||||
|
q: quit
|
||||||
|
h: help
|
||||||
|
r: reload
|
||||||
|
s: view source code of page
|
||||||
|
i: visit root index of this host eg: root index of mttp://deadvey.com/blog/4.md is just deadvey.com
|
||||||
|
b: go back in history
|
||||||
|
f: go forward in history
|
||||||
|
ox: print the hyprlink of reference x eg: o5 or o24
|
||||||
|
[url]: follow the inputed url");
|
||||||
}
|
}
|
||||||
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..];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user