Browse Source

Better text wrapping

tags/0.8.15
Julien Blanchard 10 months ago
parent
commit
0c2e3e2f4e
2 changed files with 15 additions and 16 deletions
  1. 1
    2
      src/castor.glade
  2. 14
    14
      src/draw.rs

+ 1
- 2
src/castor.glade View File

@@ -53,8 +53,8 @@
53 53
                 <property name="margin_bottom">15</property>
54 54
                 <property name="image">image3</property>
55 55
                 <property name="always_show_image">True</property>
56
+                <accelerator key="Back" signal="clicked"/>
56 57
                 <accelerator key="Left" signal="clicked" modifiers="GDK_MOD1_MASK"/>
57
-                <accelerator key="XF86Back" signal="clicked"/>
58 58
               </object>
59 59
               <packing>
60 60
                 <property name="expand">False</property>
@@ -139,7 +139,6 @@
139 139
                 <property name="app_paintable">True</property>
140 140
                 <property name="can_focus">True</property>
141 141
                 <property name="editable">False</property>
142
-                <property name="wrap_mode">word</property>
143 142
                 <property name="left_margin">10</property>
144 143
                 <property name="right_margin">10</property>
145 144
                 <property name="top_margin">5</property>

+ 14
- 14
src/draw.rs View File

@@ -10,6 +10,7 @@ extern crate textwrap;
10 10
 use textwrap::fill;
11 11
 
12 12
 use crate::absolute_url::AbsoluteUrl;
13
+use crate::colors::*;
13 14
 use crate::gemini::link::Link as GeminiLink;
14 15
 use crate::gopher::link::Link as GopherLink;
15 16
 use crate::gui::Gui;
@@ -102,12 +103,12 @@ pub fn gemini_content(
102 103
                           crate::settings::get_gemini_list_font_family(),
103 104
                           crate::settings::get_gemini_list_font_style(),
104 105
                           crate::settings::get_list_character(),
105
-                          escape_text(&item)
106
+                          wrap_text(&item, &gui)
106 107
                       ),
107 108
                   );
108 109
                 }
109 110
             }
110
-            Ok(crate::gemini::parser::TextElement::Quote(mut text)) => {
111
+            Ok(crate::gemini::parser::TextElement::Quote(text)) => {
111 112
                 let mut end_iter = buffer.get_end_iter();
112 113
                 if mono_toggle {
113 114
                     buffer.insert_markup(&mut end_iter, &mono_span(text));
@@ -121,7 +122,7 @@ pub fn gemini_content(
121 122
                             crate::settings::get_gemini_quote_font_family(),
122 123
                             crate::settings::get_gemini_quote_font_size(),
123 124
                             crate::settings::get_gemini_quote_font_style(),
124
-                            fill(&text.split_off(2), width(&gui))
125
+                            wrap_text(&text, &gui)
125 126
                         ),
126 127
                     );
127 128
                 }
@@ -129,7 +130,7 @@ pub fn gemini_content(
129 130
             Ok(crate::gemini::parser::TextElement::Text(text)) => {
130 131
                 let mut end_iter = buffer.get_end_iter();
131 132
                 if mono_toggle {
132
-                    buffer.insert_markup(&mut end_iter, &mono_span(escape_text(&text)));
133
+                    buffer.insert_markup(&mut end_iter, &mono_span(colors::colorize(&text)));
133 134
                 } else {
134 135
                     buffer.insert_markup(
135 136
                         &mut end_iter,
@@ -138,7 +139,7 @@ pub fn gemini_content(
138 139
                             crate::settings::get_text_color(),
139 140
                             font_family,
140 141
                             crate::settings::get_gemini_text_font_size(),
141
-                            fill(&escape_text(&text), width(&gui))
142
+                            wrap_text(&text, &gui)
142 143
                         ),
143 144
                     );
144 145
                 }
@@ -168,7 +169,7 @@ pub fn gemini_text_content(gui: &Arc<Gui>, content: std::str::Lines) -> TextBuff
168 169
             &format!(
169 170
                 "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
170 171
                 crate::settings::get_text_color(),
171
-                escape_text(&line)
172
+                colors::colorize(&line)
172 173
             ),
173 174
         );
174 175
     }
@@ -186,12 +187,7 @@ pub fn gopher_content(
186 187
         match el {
187 188
             Ok(crate::gopher::parser::TextElement::Text(text)) => {
188 189
                 let mut end_iter = buffer.get_end_iter();
189
-
190
-                let text = if text.contains("<span") {
191
-                    text
192
-                } else {
193
-                    escape_text(&text)
194
-                };
190
+                let text = colors::colorize(&text);
195 191
 
196 192
                 buffer.insert_markup(
197 193
                     &mut end_iter,
@@ -205,10 +201,10 @@ pub fn gopher_content(
205 201
                 );
206 202
             }
207 203
             Ok(crate::gopher::parser::TextElement::LinkItem(link_item)) => {
208
-                gopher_link(&gui, link_item);
204
+                gopher_link(&gui, colors::cleanup(&link_item));
209 205
             }
210 206
             Ok(crate::gopher::parser::TextElement::ExternalLinkItem(link_item)) => {
211
-                gopher_link(&gui, link_item);
207
+                gopher_link(&gui, colors::cleanup(&link_item));
212 208
             }
213 209
             Ok(crate::gopher::parser::TextElement::Image(link_item)) => {
214 210
                 gopher_link(&gui, link_item);
@@ -439,6 +435,10 @@ pub fn insert_external_button(gui: &Arc<Gui>, url: Url, label: &str) {
439 435
     buffer.insert(&mut end_iter, "\n");
440 436
 }
441 437
 
438
+fn wrap_text(str: &str, gui: &Arc<Gui>) -> String {
439
+    fill(&escape_text(str), width(&gui))
440
+}
441
+
442 442
 fn escape_text(str: &str) -> String {
443 443
     String::from(glib::markup_escape_text(&str).as_str())
444 444
 }

Loading…
Cancel
Save