~exprez135/castor

c8675c834f32afb25b55d582aae17b955bfc5ad5 — Julien Blanchard 1 year, 5 months ago d401d48 0.8.3
Don't parse Gemini plain text files, bring colors back to gopher
4 files changed, 22 insertions(+), 25 deletions(-)

M Cargo.lock
M Cargo.toml
M src/draw.rs
M src/main.rs
M Cargo.lock => Cargo.lock +1 -1
@@ 136,7 136,7 @@ dependencies = [

[[package]]
name = "castor"
version = "0.8.2"
version = "0.8.3"
dependencies = [
 "ansi-parser 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",

M Cargo.toml => Cargo.toml +1 -1
@@ 1,6 1,6 @@
[package]
name = "castor"
version = "0.8.2"
version = "0.8.3"
authors = ["Julien Blanchard <julien@typed-hole.org>"]
edition = "2018"


M src/draw.rs => src/draw.rs +18 -21
@@ 120,29 120,20 @@ pub fn gemini_content(
    buffer
}

pub fn gemini_text_content(
    gui: &Arc<Gui>,
    content: Vec<Result<crate::gemini::parser::TextElement, crate::gemini::parser::ParseError>>,
) -> TextBuffer {
pub fn gemini_text_content(gui: &Arc<Gui>, content: std::str::Lines) -> TextBuffer {
    let content_view = gui.content_view();
    let buffer = content_view.get_buffer().unwrap();

    for el in content {
        match el {
            Ok(crate::gemini::parser::TextElement::Text(text)) => {
                let mut end_iter = buffer.get_end_iter();
                buffer.insert_markup(
                    &mut end_iter,
                    &format!(
                        "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
                        crate::settings::text_color(),
                        escape_text(&text)
                    ),
                );
            }
            Ok(_) => (),
            Err(_) => println!("Something failed."),
        }
    for line in content {
        let mut end_iter = buffer.get_end_iter();
        buffer.insert_markup(
            &mut end_iter,
            &format!(
                "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
                crate::settings::text_color(),
                escape_text(&line)
            ),
        );
    }
    buffer
}


@@ 164,13 155,19 @@ pub fn gopher_content(
                    "font_family=\"serif\""
                };

                let text = if text.contains("<span") {
                    text
                } else {
                    escape_text(&text)
                };

                buffer.insert_markup(
                    &mut end_iter,
                    &format!(
                        "<span foreground=\"{}\" {}>{}</span>\n",
                        crate::settings::text_color(),
                        font_family,
                        escape_text(&text)
                        text
                    ),
                );
            }

M src/main.rs => src/main.rs +2 -2
@@ 204,13 204,13 @@ pub fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
                                        let content_str =
                                            String::from_utf8_lossy(&new_content).to_string();

                                        let parsed_content = gemini::parser::parse(content_str);
                                        clear_buffer(&content_view);
                                        if meta == "text/gemini" {
                                            let parsed_content = gemini::parser::parse(content_str);
                                            draw::gemini_content(&gui, parsed_content);
                                        } else {
                                            // just a text file
                                            draw::gemini_text_content(&gui, parsed_content);
                                            draw::gemini_text_content(&gui, content_str.lines());
                                        }

                                        content_view.show_all();