Browse Source

Don't parse Gemini plain text files, bring colors back to gopher

tags/0.8.3^0
Julien Blanchard 1 year ago
parent
commit
c8675c834f
4 changed files with 22 additions and 25 deletions
  1. 1
    1
      Cargo.lock
  2. 1
    1
      Cargo.toml
  3. 18
    21
      src/draw.rs
  4. 2
    2
      src/main.rs

+ 1
- 1
Cargo.lock View File

@@ -136,7 +136,7 @@ dependencies = [
136 136
 
137 137
 [[package]]
138 138
 name = "castor"
139
-version = "0.8.2"
139
+version = "0.8.3"
140 140
 dependencies = [
141 141
  "ansi-parser 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
142 142
  "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",

+ 1
- 1
Cargo.toml View File

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

+ 18
- 21
src/draw.rs View File

@@ -120,29 +120,20 @@ pub fn gemini_content(
120 120
     buffer
121 121
 }
122 122
 
123
-pub fn gemini_text_content(
124
-    gui: &Arc<Gui>,
125
-    content: Vec<Result<crate::gemini::parser::TextElement, crate::gemini::parser::ParseError>>,
126
-) -> TextBuffer {
123
+pub fn gemini_text_content(gui: &Arc<Gui>, content: std::str::Lines) -> TextBuffer {
127 124
     let content_view = gui.content_view();
128 125
     let buffer = content_view.get_buffer().unwrap();
129 126
 
130
-    for el in content {
131
-        match el {
132
-            Ok(crate::gemini::parser::TextElement::Text(text)) => {
133
-                let mut end_iter = buffer.get_end_iter();
134
-                buffer.insert_markup(
135
-                    &mut end_iter,
136
-                    &format!(
137
-                        "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
138
-                        crate::settings::text_color(),
139
-                        escape_text(&text)
140
-                    ),
141
-                );
142
-            }
143
-            Ok(_) => (),
144
-            Err(_) => println!("Something failed."),
145
-        }
127
+    for line in content {
128
+        let mut end_iter = buffer.get_end_iter();
129
+        buffer.insert_markup(
130
+            &mut end_iter,
131
+            &format!(
132
+                "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
133
+                crate::settings::text_color(),
134
+                escape_text(&line)
135
+            ),
136
+        );
146 137
     }
147 138
     buffer
148 139
 }
@@ -164,13 +155,19 @@ pub fn gopher_content(
164 155
                     "font_family=\"serif\""
165 156
                 };
166 157
 
158
+                let text = if text.contains("<span") {
159
+                    text
160
+                } else {
161
+                    escape_text(&text)
162
+                };
163
+
167 164
                 buffer.insert_markup(
168 165
                     &mut end_iter,
169 166
                     &format!(
170 167
                         "<span foreground=\"{}\" {}>{}</span>\n",
171 168
                         crate::settings::text_color(),
172 169
                         font_family,
173
-                        escape_text(&text)
170
+                        text
174 171
                     ),
175 172
                 );
176 173
             }

+ 2
- 2
src/main.rs View File

@@ -204,13 +204,13 @@ pub fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
204 204
                                         let content_str =
205 205
                                             String::from_utf8_lossy(&new_content).to_string();
206 206
 
207
-                                        let parsed_content = gemini::parser::parse(content_str);
208 207
                                         clear_buffer(&content_view);
209 208
                                         if meta == "text/gemini" {
209
+                                            let parsed_content = gemini::parser::parse(content_str);
210 210
                                             draw::gemini_content(&gui, parsed_content);
211 211
                                         } else {
212 212
                                             // just a text file
213
-                                            draw::gemini_text_content(&gui, parsed_content);
213
+                                            draw::gemini_text_content(&gui, content_str.lines());
214 214
                                         }
215 215
 
216 216
                                         content_view.show_all();

Loading…
Cancel
Save