-- Leo's gemini proxy

-- Connecting to typed-hole.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

commit b1d2906f761d3031d3e28c4fd2efbbd843287a2a

Author: Julien Blanchard <julien@sideburns.eu>

Date: Mon Aug 12 11:41:01 2019 +0200


Display/handle different schemes


diff --git a/src/link.rs b/src/link.rs

index 2e976dd..5c1e102 100644

--- a/src/link.rs

+++ b/src/link.rs

@@ -1,12 +1,15 @@

extern crate regex;

use regex::Regex;

-

+use url::Url;

use std::str::FromStr;


-pub struct Link {

- pub url: String,

- pub label: String,

+pub enum Link {

+ Gemini(Url, String),

+ Gopher(Url, String),

+ Http(Url, String),

+ Relative(String, String),

+ Unknown(Url, String),

}


Clone, Copy, PartialEq, Eq, Hash)]

@@ -33,9 +36,31 @@ impl FromStr for Link {

label_str.to_string()

};


- Ok(Link { url, label })

+ match make_link(url, label) {

+ Some(link) => Ok(link),

+ None => Err(ParseError),

+ }

}

None => Err(ParseError),

}

}

}

+

+fn make_link(url: String, label: String) -> Option<Link> {

+ let urlp = Url::parse(&url);

+ match urlp {

+ Ok(url) => {

+ match url.scheme() {

+ "gemini" => Some(Link::Gemini(url, label)),

+ "gopher" => Some(Link::Gopher(url, label)),

+ "http" => Some(Link::Http(url, label)),

+ "https" => Some(Link::Http(url, label)),

+ _ => Some(Link::Unknown(url, label))

+ }

+ },

+ Err(url::ParseError::RelativeUrlWithoutBase) => {

+ Some(Link::Relative(url, label))

+ },

+ _ => None

+ }

+}

diff --git a/src/main.rs b/src/main.rs

index 2685e91..105e6de 100644

--- a/src/main.rs

+++ b/src/main.rs

@@ -24,7 +24,7 @@ use link::Link;

mod content;

mod history;


-const HELP: &'static str = "

+const HELP: &str = "

Welcome to Asuka Gemini browser!


Press g to visit an URL

@@ -142,6 +142,7 @@ fn draw_content(s: &mut Cursive, url: Url, content: String) {

container.set_title(url.as_str());

main_view.clear();


+ // handle statuses here

match Status::from_str(content.lines().next().unwrap()) {

Ok(_status) => {}

Err(_) => {}

@@ -150,12 +151,37 @@ fn draw_content(s: &mut Cursive, url: Url, content: String) {

for line in content.lines().skip(1) {

match Link::from_str(line) {

Ok(link) => {

- let mut formatted = StyledString::new();

- formatted.append(StyledString::styled(link.label, Effect::Underline));

-

- main_view.add_item(formatted, link.url)

+ match link {

+ Link::Http(_url, label) => {

+ let mut formatted = StyledString::new();

+ let gopher_label = format!("[WWW] {}", label);

+ formatted.append(StyledString::styled(gopher_label, Effect::Italic));

+

+ main_view.add_item(formatted, String::from("0"))

+ },

+ Link::Gopher(_url, label) => {

+ let mut formatted = StyledString::new();

+ let gopher_label = format!("[Gopher] {}", label);

+ formatted.append(StyledString::styled(gopher_label, Effect::Italic));

+

+ main_view.add_item(formatted, String::from("0"))

+ },

+ Link::Gemini(url, label) => {

+ let mut formatted = StyledString::new();

+ formatted.append(StyledString::styled(label, Effect::Underline));

+

+ main_view.add_item(formatted, url.to_string())

+ },

+ Link::Relative(url, label) => {

+ let mut formatted = StyledString::new();

+ formatted.append(StyledString::styled(label, Effect::Underline));

+

+ main_view.add_item(formatted, url.to_string())

+ },

+ _ => ()

+ }

}

- Err(_) => main_view.add_item(str::replace(line, "\t", " "), "0".to_owned()),

+ Err(_) => main_view.add_item(str::replace(line, "\t", " "), String::from("0")),

}

}

}

@@ -168,8 +194,6 @@ fn follow_link(s: &mut Cursive, line: &str) {

if is_gemini_link(line) {

let next_url = make_absolute(line).expect("Not an URL");

visit_url(s, &next_url)

- } else {

- ()

}

}


@@ -179,7 +203,7 @@ fn make_absolute(url: &str) -> Result<url::Url, url::ParseError> {

Some(host) => {

if url.starts_with("gemini://") {

Url::parse(url)

- } else if url.starts_with("/") {

+ } else if url.starts_with('/') {

Url::parse(&format!("gemini://{}{}", host, url))

} else {

Url::parse(&format!("gemini://{}/{}", host, url))



---

Served by Pollux Gemini Server.

-- Response ended

-- Page fetched on Sun May 19 10:28:16 2024