-- Leo's gemini proxy
-- Connecting to typed-hole.org:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
commit da8950408009a7cae6423699f348f081248ef67c
Author: Julien Blanchard <julien@sideburns.eu>
Date: Sun Apr 19 16:56:44 2020 +0200
[finger] now a first class citizen
has it's own parsing and drawing routines
diff --git a/src/finger/mod.rs b/src/finger/mod.rs
index b9babe5..71962fe 100644
--- a/src/finger/mod.rs
+++ b/src/finger/mod.rs
@@ -1 +1,2 @@
pub mod client;
+pub mod parser;
diff --git a/src/finger/parser.rs b/src/finger/parser.rs
new file mode 100644
index 0000000..d5d853f
--- /dev/null
+++ b/src/finger/parser.rs
@@ -0,0 +1,27 @@
+use std::str::FromStr;
+
+#[derive(Debug)]
+pub enum TextElement {
+ Text(String),
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct ParseError;
+
+impl FromStr for TextElement {
+ type Err = ParseError;
+
+ // Parses a &str into an instance of 'TextElement'
+ fn from_str(line: &str) -> Result<TextElement, ParseError> {
+ Ok(TextElement::Text(line.to_string()))
+ }
+}
+
+pub fn parse(content: String) -> Vec<Result<TextElement, ParseError>> {
+ let mut parsed = Vec::new();
+
+ for line in content.lines() {
+ parsed.push(TextElement::from_str(line));
+ }
+ parsed
+}
diff --git a/src/main.rs b/src/main.rs
index db6c8ca..456da9c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -263,9 +263,9 @@ fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
update_url_field(&gui, abs_url.as_str());
let content_str = String::from_utf8_lossy(&new_content).to_string();
- let parsed_content = gopher::parser::parse(content_str);
+ let parsed_content = finger::parser::parse(content_str);
clear_buffer(&content_view);
- draw_gopher_content(&gui, parsed_content);
+ draw_finger_content(&gui, parsed_content);
content_view.show_all();
}
@@ -384,6 +384,28 @@ fn draw_gopher_content(
buffer
}
+fn draw_finger_content(
+ gui: &Arc<Gui>,
+ content: Vec<Result<finger::parser::TextElement, finger::parser::ParseError>>,
+) -> TextBuffer {
+ let content_view = gui.content_view();
+ let buffer = content_view.get_buffer().unwrap();
+
+ for el in content {
+ match el {
+ Ok(finger::parser::TextElement::Text(text)) => {
+ let mut end_iter = buffer.get_end_iter();
+ buffer.insert_markup(
+ &mut end_iter,
+ &format!("<span font_family=\"monospace\">{}</span>\n", text),
+ );
+ }
+ Err(_) => println!("Something failed."),
+ }
+ }
+ buffer
+}
+
fn draw_gemini_link(gui: &Arc<Gui>, link_item: String) {
match GeminiLink::from_str(&link_item) {
Ok(GeminiLink::Finger(url, label)) => {
---
Served by Pollux Gemini Server.
-- Response ended
-- Page fetched on Sun May 19 04:53:36 2024