From 5f856f35feb84a3aea58242b52eb1f2b990ca65f Mon Sep 17 00:00:00 2001 From: deadvey Date: Sun, 26 Jan 2025 02:59:06 +0000 Subject: [PATCH] source code viewing --- src/main.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9407a5c..2659a30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,13 +153,16 @@ fn fetch_page(url: &Url) -> String { } } -fn render_page(url: Url) -> Vec { +fn render_page(url: Url, source: bool) -> Vec { clear_screen(); let mut content = fetch_page(&url); let mut links = Vec::new(); let (screen_width, _screen_height) = termion::terminal_size().unwrap(); - if &content[..13] == "" { + if source == true { + content += &format!("{}", &"Viewing source code".yellow()); + } + else if &content[..13] == "" { (content, links) = parse_markdown((&content[13..]).to_string()); } else { @@ -239,11 +242,12 @@ fn main() { let mut history: Vec = Vec::new(); let mut historical_position: usize = 0; let mut links: Vec = 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 ;) history.push(url.clone()); 'mainloop: loop { 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"); } load_page = false; @@ -256,6 +260,19 @@ fn main() { load_page = true; 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" { if historical_position > 0 { historical_position -= 1; @@ -275,7 +292,16 @@ fn main() { } } 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' { let number_str = &user_input[1..];