Browse Source

Font are customizable

- Can change family (sans/serif/monospace)
- Can change size
- Can change style (normal/italic/oblique)
tags/0.8.9^0
Julien Blanchard 11 months ago
parent
commit
67a3ae1c40
11 changed files with 406 additions and 152 deletions
  1. 2
    1
      Cargo.lock
  2. 2
    1
      Cargo.toml
  3. 27
    6
      README.md
  4. 26
    5
      data/castor_settings.toml.example
  5. 40
    42
      src/draw.rs
  6. 3
    3
      src/finger/client.rs
  7. 2
    2
      src/gemini/client.rs
  8. 8
    0
      src/gopher/link.rs
  9. 6
    1
      src/gopher/parser.rs
  10. 3
    1
      src/main.rs
  11. 287
    90
      src/settings.rs

+ 2
- 1
Cargo.lock View File

@@ -112,7 +112,7 @@ dependencies = [
112 112
 
113 113
 [[package]]
114 114
 name = "castor"
115
-version = "0.8.8"
115
+version = "0.8.9"
116 116
 dependencies = [
117 117
  "ansi-parser",
118 118
  "dirs",
@@ -127,6 +127,7 @@ dependencies = [
127 127
  "open",
128 128
  "openssl",
129 129
  "pango",
130
+ "pango-sys",
130 131
  "percent-encoding",
131 132
  "regex",
132 133
  "serde",

+ 2
- 1
Cargo.toml View File

@@ -1,6 +1,6 @@
1 1
 [package]
2 2
 name = "castor"
3
-version = "0.8.8"
3
+version = "0.8.9"
4 4
 authors = ["Julien Blanchard <julien@typed-hole.org>"]
5 5
 edition = "2018"
6 6
 
@@ -13,6 +13,7 @@ gio = "*"
13 13
 glib = "*"
14 14
 glib-sys = "*"
15 15
 pango = "*"
16
+pango-sys = "*"
16 17
 open = "*"
17 18
 regex = "*"
18 19
 native-tls = "*"

+ 27
- 6
README.md View File

@@ -82,12 +82,33 @@ background = "#FFC0CB"
82 82
 h1 = ">"
83 83
 h2 = "))"
84 84
 h3 = "}}}"
85
-list = "🌼"
86
-
87
-[monospace]
88
-gemini=false
89
-gopher=true
90
-finger=true
85
+list = "🌼 "
86
+
87
+[fonts]
88
+[fonts.finger]
89
+    family = "monospace"
90
+    size = 11
91
+[fonts.gemini]
92
+    family = "serif"
93
+    size = 11
94
+[fonts.gemini.h1]
95
+    family = "sans"
96
+    size = 16
97
+    style = "normal"
98
+[fonts.gemini.h2]
99
+    family = "monospace"
100
+    size = 13
101
+    style = "italic"
102
+[fonts.gemini.h3]
103
+    family = "monospace"
104
+    size = 12
105
+[fonts.gemini.list]
106
+    family = "sans"
107
+    size = 11
108
+    style = "oblique"
109
+[fonts.gopher]
110
+    family = "monospace"
111
+    size = 11
91 112
 ```
92 113
 
93 114
 

+ 26
- 5
data/castor_settings.toml.example View File

@@ -13,9 +13,30 @@ background = "#FFC0CB"
13 13
 h1 = ">"
14 14
 h2 = "))"
15 15
 h3 = "}}}"
16
-list = "🌼"
16
+list = "🌼 "
17 17
 
18
-[monospace]
19
-gemini=false
20
-gopher=true
21
-finger=true
18
+[fonts]
19
+[fonts.finger]
20
+    family = "monospace"
21
+    size = 11
22
+[fonts.gemini]
23
+    family = "serif"
24
+    size = 11
25
+[fonts.gemini.h1]
26
+    family = "sans"
27
+    size = 16
28
+    style = "normal"
29
+[fonts.gemini.h2]
30
+    family = "monospace"
31
+    size = 13
32
+    style = "italic"
33
+[fonts.gemini.h3]
34
+    family = "monospace"
35
+    size = 12
36
+[fonts.gemini.list]
37
+    family = "sans"
38
+    size = 11
39
+    style = "oblique"
40
+[fonts.gopher]
41
+    family = "monospace"
42
+    size = 11

+ 40
- 42
src/draw.rs View File

@@ -19,11 +19,7 @@ pub fn gemini_content(
19 19
     let buffer = content_view.get_buffer().unwrap();
20 20
 
21 21
     let mut mono_toggle = false;
22
-    let font_family = if crate::settings::gemini_monospace() {
23
-        "monospace"
24
-    } else {
25
-        "sans"
26
-    };
22
+    let font_family = crate::settings::get_gemini_text_font_family();
27 23
 
28 24
     for el in content {
29 25
         match el {
@@ -32,10 +28,12 @@ pub fn gemini_content(
32 28
                 buffer.insert_markup(
33 29
                     &mut end_iter,
34 30
                     &format!(
35
-                        "<span foreground=\"{}\" size=\"x-large\" font_family=\"{}\">{}{}</span>\n",
36
-                        crate::settings::h1_color(),
37
-                        font_family,
38
-                        crate::settings::h1_character(),
31
+                        "<span foreground=\"{}\" size=\"{}\" font_family=\"{}\" style=\"{}\">{}{}</span>\n",
32
+                        crate::settings::get_h1_color(),
33
+                        crate::settings::get_gemini_h1_font_size(),
34
+                        crate::settings::get_gemini_h1_font_family(),
35
+                        crate::settings::get_gemini_h1_font_style(),
36
+                        crate::settings::get_h1_character(),
39 37
                         escape_text(&header)
40 38
                     ),
41 39
                 );
@@ -45,10 +43,12 @@ pub fn gemini_content(
45 43
                 buffer.insert_markup(
46 44
                     &mut end_iter,
47 45
                     &format!(
48
-                        "<span foreground=\"{}\" size=\"large\" font_family=\"{}\">{}{}</span>\n",
49
-                        crate::settings::h2_color(),
50
-                        font_family,
51
-                        crate::settings::h2_character(),
46
+                        "<span foreground=\"{}\" size=\"{}\" font_family=\"{}\" style=\"{}\">{}{}</span>\n",
47
+                        crate::settings::get_h2_color(),
48
+                        crate::settings::get_gemini_h2_font_size(),
49
+                        crate::settings::get_gemini_h2_font_family(),
50
+                        crate::settings::get_gemini_h2_font_style(),
51
+                        crate::settings::get_h2_character(),
52 52
                         escape_text(&header)
53 53
                     ),
54 54
                 );
@@ -58,10 +58,12 @@ pub fn gemini_content(
58 58
                 buffer.insert_markup(
59 59
                     &mut end_iter,
60 60
                     &format!(
61
-                        "<span foreground=\"{}\" size=\"medium\" font_family=\"{}\">{}{}</span>\n",
62
-                        crate::settings::h3_color(),
63
-                        font_family,
64
-                        crate::settings::h3_character(),
61
+                        "<span foreground=\"{}\" size=\"{}\" font_family=\"{}\" style=\"{}\">{}{}</span>\n",
62
+                        crate::settings::get_h3_color(),
63
+                        crate::settings::get_gemini_h3_font_size(),
64
+                        crate::settings::get_gemini_h3_font_family(),
65
+                        crate::settings::get_gemini_h3_font_style(),
66
+                        crate::settings::get_h3_character(),
65 67
                         escape_text(&header)
66 68
                     ),
67 69
                 );
@@ -71,10 +73,12 @@ pub fn gemini_content(
71 73
                 buffer.insert_markup(
72 74
                     &mut end_iter,
73 75
                     &format!(
74
-                        "<span foreground=\"{}\" font_family=\"{}\">{} {}</span>\n",
75
-                        crate::settings::list_color(),
76
-                        font_family,
77
-                        crate::settings::list_character(),
76
+                        "<span foreground=\"{}\" size=\"{}\" font_family=\"{}\" style=\"{}\">{}{}</span>\n",
77
+                        crate::settings::get_list_color(),
78
+                        crate::settings::get_gemini_list_font_size(),
79
+                        crate::settings::get_gemini_list_font_family(),
80
+                        crate::settings::get_gemini_list_font_style(),
81
+                        crate::settings::get_list_character(),
78 82
                         escape_text(&item)
79 83
                     ),
80 84
                 );
@@ -94,8 +98,9 @@ pub fn gemini_content(
94 98
                     buffer.insert_markup(
95 99
                         &mut end_iter,
96 100
                         &format!(
97
-                            "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
98
-                            crate::settings::text_color(),
101
+                            "<span foreground=\"{}\" font_family=\"monospace\" size=\"{}\">{}</span>\n",
102
+                            crate::settings::get_text_color(),
103
+                            crate::settings::get_gemini_text_font_size(),
99 104
                             text
100 105
                         ),
101 106
                     );
@@ -103,9 +108,10 @@ pub fn gemini_content(
103 108
                     buffer.insert_markup(
104 109
                         &mut end_iter,
105 110
                         &format!(
106
-                            "<span foreground=\"{}\" font_family=\"{}\">{}</span>\n",
107
-                            crate::settings::text_color(),
111
+                            "<span foreground=\"{}\" font_family=\"{}\" size=\"{}\">{}</span>\n",
112
+                            crate::settings::get_text_color(),
108 113
                             font_family,
114
+                            crate::settings::get_gemini_text_font_size(),
109 115
                             text
110 116
                         ),
111 117
                     );
@@ -130,7 +136,7 @@ pub fn gemini_text_content(gui: &Arc<Gui>, content: std::str::Lines) -> TextBuff
130 136
             &mut end_iter,
131 137
             &format!(
132 138
                 "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
133
-                crate::settings::text_color(),
139
+                crate::settings::get_text_color(),
134 140
                 escape_text(&line)
135 141
             ),
136 142
         );
@@ -149,11 +155,6 @@ pub fn gopher_content(
149 155
         match el {
150 156
             Ok(crate::gopher::parser::TextElement::Text(text)) => {
151 157
                 let mut end_iter = buffer.get_end_iter();
152
-                let font_family = if crate::settings::gopher_monospace() {
153
-                    "font_family=\"monospace\""
154
-                } else {
155
-                    "font_family=\"serif\""
156
-                };
157 158
 
158 159
                 let text = if text.contains("<span") {
159 160
                     text
@@ -164,9 +165,10 @@ pub fn gopher_content(
164 165
                 buffer.insert_markup(
165 166
                     &mut end_iter,
166 167
                     &format!(
167
-                        "<span foreground=\"{}\" {}>{}</span>\n",
168
-                        crate::settings::text_color(),
169
-                        font_family,
168
+                        "<span foreground=\"{}\" font_family=\"{}\" size=\"{}\">{}</span>\n",
169
+                        crate::settings::get_text_color(),
170
+                        crate::settings::get_gopher_font_family(),
171
+                        crate::settings::get_gopher_font_size(),
170 172
                         text
171 173
                     ),
172 174
                 );
@@ -200,18 +202,14 @@ pub fn finger_content(
200 202
         match el {
201 203
             Ok(crate::finger::parser::TextElement::Text(text)) => {
202 204
                 let mut end_iter = buffer.get_end_iter();
203
-                let font_family = if crate::settings::finger_monospace() {
204
-                    "font_family=\"monospace\""
205
-                } else {
206
-                    "font_family=\"serif\""
207
-                };
208 205
 
209 206
                 buffer.insert_markup(
210 207
                     &mut end_iter,
211 208
                     &format!(
212
-                        "<span foreground=\"{}\" {}>{}</span>\n",
213
-                        crate::settings::text_color(),
214
-                        font_family,
209
+                        "<span foreground=\"{}\" font_family=\"{}\" size=\"{}\">{}</span>\n",
210
+                        crate::settings::get_text_color(),
211
+                        crate::settings::get_finger_font_family(),
212
+                        crate::settings::get_finger_font_size(),
215 213
                         escape_text(&text)
216 214
                     ),
217 215
                 );

+ 3
- 3
src/finger/client.rs View File

@@ -37,13 +37,13 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
37 37
 
38 38
                         Ok((None, res))
39 39
                     })
40
-                        .join()
41
-                        .unwrap(),
40
+                    .join()
41
+                    .unwrap(),
42 42
                     Err(e) => Err(format!("Could not connect to {}\n{}", urlf, e)),
43 43
                 }
44 44
             }
45 45
             None => Err(format!("Could not connect to {}\n", urlf)),
46
-        }
46
+        },
47 47
         Err(e) => Err(format!("Could not connect to {}\n{}", urlf, e)),
48 48
     }
49 49
 }

+ 2
- 2
src/gemini/client.rs View File

@@ -31,8 +31,8 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
31 31
                     V4(ip) => V4(ip),
32 32
                     V6(ip) => match addrs_iter.next() {
33 33
                         Some(addr) => addr,
34
-                        None => V6(ip)
35
-                    }
34
+                        None => V6(ip),
35
+                    },
36 36
                 };
37 37
 
38 38
                 let stream = TcpStream::connect_timeout(&socket_addr, Duration::new(5, 0));

+ 8
- 0
src/gopher/link.rs View File

@@ -170,6 +170,14 @@ impl FromStr for Link {
170 170
             } else {
171 171
                 Err(ParseError)
172 172
             }
173
+        // } else if line.contains("://") {
174
+        //     let url = extract_url(line);
175
+        //     let label = String::from(line);
176
+
177
+        //     match make_link(String::from(url), label) {
178
+        //         Some(link) => Ok(link),
179
+        //         None => Err(ParseError),
180
+        //     }
173 181
         } else {
174 182
             Err(ParseError)
175 183
         }

+ 6
- 1
src/gopher/parser.rs View File

@@ -42,7 +42,12 @@ impl FromStr for TextElement {
42 42
             // Text line
43 43
             if line.contains("gopher://") {
44 44
                 Ok(TextElement::LinkItem(String::from(line)))
45
-            } else if line.contains("http://") || line.contains("https://") || line.contains("gemini://") || line.contains("finger://") || line.contains("ftp://") {
45
+            } else if line.contains("http://")
46
+                || line.contains("https://")
47
+                || line.contains("gemini://")
48
+                || line.contains("finger://")
49
+                || line.contains("ftp://")
50
+            {
46 51
                 Ok(TextElement::ExternalLinkItem(String::from(line)))
47 52
             } else {
48 53
                 Ok(TextElement::Text(colors::colorize(line)))

+ 3
- 1
src/main.rs View File

@@ -190,7 +190,9 @@ pub fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
190 190
             let absolute_url = url.to_absolute_url();
191 191
 
192 192
             match absolute_url {
193
-                Ok(absolute_url) => match gemini::client::get_data(Gemini { source: absolute_url.to_string() }) {
193
+                Ok(absolute_url) => match gemini::client::get_data(Gemini {
194
+                    source: absolute_url.to_string(),
195
+                }) {
194 196
                     Ok((meta, new_content)) => {
195 197
                         let meta_str = String::from_utf8_lossy(&meta.unwrap()).to_string();
196 198
 

+ 287
- 90
src/settings.rs View File

@@ -12,7 +12,7 @@ struct Settings {
12 12
     general: Option<General>,
13 13
     colors: Option<Color>,
14 14
     characters: Option<Character>,
15
-    monospace: Option<Monospace>,
15
+    fonts: Option<Font>,
16 16
 }
17 17
 
18 18
 #[derive(Deserialize)]
@@ -38,11 +38,27 @@ struct Character {
38 38
     list: Option<String>,
39 39
 }
40 40
 
41
-#[derive(Deserialize)]
42
-struct Monospace {
43
-    finger: Option<bool>,
44
-    gemini: Option<bool>,
45
-    gopher: Option<bool>,
41
+#[derive(Debug, Deserialize)]
42
+struct Font {
43
+    finger: Option<FontAttr>,
44
+    gemini: Option<GeminiFontAttr>,
45
+    gopher: Option<FontAttr>,
46
+}
47
+
48
+#[derive(Debug, Deserialize)]
49
+struct FontAttr {
50
+    family: Option<String>,
51
+    style: Option<String>,
52
+    size: Option<i32>,
53
+}
54
+
55
+#[derive(Debug, Deserialize)]
56
+struct GeminiFontAttr {
57
+    text: Option<FontAttr>,
58
+    h1: Option<FontAttr>,
59
+    h2: Option<FontAttr>,
60
+    h3: Option<FontAttr>,
61
+    list: Option<FontAttr>,
46 62
 }
47 63
 
48 64
 pub fn start_url() -> Option<String> {
@@ -52,130 +68,311 @@ pub fn start_url() -> Option<String> {
52 68
     }
53 69
 }
54 70
 
55
-pub fn h1_color() -> String {
56
-    match read().colors {
57
-        Some(colors) => match colors.h1 {
58
-            Some(color) => color,
59
-            None => String::from("#9932CC"),
60
-        },
71
+const DEFAULT_FONT: &str = "serif";
72
+const DEFAULT_FONT_STYLE: &str = "normal";
73
+const DEFAULT_FONT_SIZE: i32 = 11 * pango_sys::PANGO_SCALE;
74
+const DEFAULT_H1_FONT_SIZE: i32 = 16 * pango_sys::PANGO_SCALE;
75
+const DEFAULT_H2_FONT_SIZE: i32 = 13 * pango_sys::PANGO_SCALE;
76
+const DEFAULT_H3_FONT_SIZE: i32 = 12 * pango_sys::PANGO_SCALE;
77
+
78
+fn finger_font_family() -> Option<String> {
79
+    read().fonts?.finger?.family
80
+}
81
+
82
+fn finger_font_size() -> Option<i32> {
83
+    read().fonts?.finger?.size.or(Some(DEFAULT_FONT_SIZE))
84
+}
85
+
86
+pub fn get_finger_font_family() -> String {
87
+    match finger_font_family() {
88
+        Some(family) => family,
89
+        None => String::from(DEFAULT_FONT),
90
+    }
91
+}
92
+
93
+pub fn get_finger_font_size() -> i32 {
94
+    match finger_font_size() {
95
+        Some(size) => size * pango_sys::PANGO_SCALE,
96
+        None => DEFAULT_FONT_SIZE,
97
+    }
98
+}
99
+
100
+fn gemini_text_font_family() -> Option<String> {
101
+    read().fonts?.gemini?.text?.family
102
+}
103
+
104
+pub fn get_gemini_text_font_family() -> String {
105
+    match gemini_text_font_family() {
106
+        Some(family) => family,
107
+        None => String::from(DEFAULT_FONT),
108
+    }
109
+}
110
+
111
+fn gemini_text_font_size() -> Option<i32> {
112
+    read().fonts?.gemini?.text?.size
113
+}
114
+
115
+pub fn get_gemini_text_font_size() -> i32 {
116
+    match gemini_text_font_size() {
117
+        Some(size) => size * pango_sys::PANGO_SCALE,
118
+        None => DEFAULT_FONT_SIZE,
119
+    }
120
+}
121
+
122
+fn gemini_h1_font_family() -> Option<String> {
123
+    read().fonts?.gemini?.h1?.family
124
+}
125
+
126
+fn gemini_h1_font_size() -> Option<i32> {
127
+    read().fonts?.gemini?.h1?.size
128
+}
129
+
130
+fn gemini_h1_font_style() -> Option<String> {
131
+    read().fonts?.gemini?.h1?.style
132
+}
133
+
134
+pub fn get_gemini_h1_font_size() -> i32 {
135
+    match gemini_h1_font_size() {
136
+        Some(size) => size * pango_sys::PANGO_SCALE,
137
+        None => DEFAULT_H1_FONT_SIZE,
138
+    }
139
+}
140
+
141
+pub fn get_gemini_h1_font_family() -> String {
142
+    match gemini_h1_font_family() {
143
+        Some(family) => family,
144
+        None => String::from(DEFAULT_FONT),
145
+    }
146
+}
147
+
148
+pub fn get_gemini_h1_font_style() -> String {
149
+    match gemini_h1_font_style() {
150
+        Some(style) => style,
151
+        None => String::from(DEFAULT_FONT_STYLE),
152
+    }
153
+}
154
+
155
+fn gemini_h2_font_family() -> Option<String> {
156
+    read().fonts?.gemini?.h2?.family
157
+}
158
+
159
+fn gemini_h2_font_size() -> Option<i32> {
160
+    read().fonts?.gemini?.h2?.size
161
+}
162
+
163
+fn gemini_h2_font_style() -> Option<String> {
164
+    read().fonts?.gemini?.h2?.style
165
+}
166
+
167
+pub fn get_gemini_h2_font_size() -> i32 {
168
+    match gemini_h2_font_size() {
169
+        Some(size) => size * pango_sys::PANGO_SCALE,
170
+        None => DEFAULT_H2_FONT_SIZE,
171
+    }
172
+}
173
+
174
+pub fn get_gemini_h2_font_family() -> String {
175
+    match gemini_h2_font_family() {
176
+        Some(family) => family,
177
+        None => String::from(DEFAULT_FONT),
178
+    }
179
+}
180
+
181
+pub fn get_gemini_h2_font_style() -> String {
182
+    match gemini_h2_font_style() {
183
+        Some(style) => style,
184
+        None => String::from(DEFAULT_FONT_STYLE),
185
+    }
186
+}
187
+
188
+fn gemini_h3_font_family() -> Option<String> {
189
+    read().fonts?.gemini?.h3?.family
190
+}
191
+
192
+fn gemini_h3_font_size() -> Option<i32> {
193
+    read().fonts?.gemini?.h3?.size
194
+}
195
+
196
+fn gemini_h3_font_style() -> Option<String> {
197
+    read().fonts?.gemini?.h3?.style
198
+}
199
+
200
+pub fn get_gemini_h3_font_size() -> i32 {
201
+    match gemini_h3_font_size() {
202
+        Some(size) => size * pango_sys::PANGO_SCALE,
203
+        None => DEFAULT_H3_FONT_SIZE,
204
+    }
205
+}
206
+
207
+pub fn get_gemini_h3_font_family() -> String {
208
+    match gemini_h3_font_family() {
209
+        Some(family) => family,
210
+        None => String::from(DEFAULT_FONT),
211
+    }
212
+}
213
+
214
+pub fn get_gemini_h3_font_style() -> String {
215
+    match gemini_h3_font_style() {
216
+        Some(style) => style,
217
+        None => String::from(DEFAULT_FONT_STYLE),
218
+    }
219
+}
220
+
221
+fn gemini_list_font_family() -> Option<String> {
222
+    read().fonts?.gemini?.list?.family
223
+}
224
+
225
+fn gemini_list_font_size() -> Option<i32> {
226
+    read().fonts?.gemini?.list?.size
227
+}
228
+
229
+fn gemini_list_font_style() -> Option<String> {
230
+    read().fonts?.gemini?.list?.style
231
+}
232
+
233
+pub fn get_gemini_list_font_size() -> i32 {
234
+    match gemini_list_font_size() {
235
+        Some(size) => size * pango_sys::PANGO_SCALE,
236
+        None => DEFAULT_FONT_SIZE,
237
+    }
238
+}
239
+
240
+pub fn get_gemini_list_font_family() -> String {
241
+    match gemini_list_font_family() {
242
+        Some(family) => family,
243
+        None => String::from(DEFAULT_FONT),
244
+    }
245
+}
246
+
247
+pub fn get_gemini_list_font_style() -> String {
248
+    match gemini_list_font_style() {
249
+        Some(style) => style,
250
+        None => String::from(DEFAULT_FONT_STYLE),
251
+    }
252
+}
253
+
254
+fn gopher_font_family() -> Option<String> {
255
+    read().fonts?.gopher?.family
256
+}
257
+
258
+fn gopher_font_size() -> Option<i32> {
259
+    read().fonts?.gopher?.size
260
+}
261
+
262
+pub fn get_gopher_font_family() -> String {
263
+    match gopher_font_family() {
264
+        Some(family) => family,
265
+        None => String::from(DEFAULT_FONT),
266
+    }
267
+}
268
+
269
+pub fn get_gopher_font_size() -> i32 {
270
+    match gopher_font_size() {
271
+        Some(size) => size * pango_sys::PANGO_SCALE,
272
+        None => DEFAULT_FONT_SIZE,
273
+    }
274
+}
275
+
276
+fn h1_color() -> Option<String> {
277
+    read().colors?.h1
278
+}
279
+
280
+pub fn get_h1_color() -> String {
281
+    match h1_color() {
282
+        Some(color) => color,
61 283
         None => String::from("#9932CC"),
62 284
     }
63 285
 }
64 286
 
65
-pub fn h2_color() -> String {
66
-    match read().colors {
67
-        Some(colors) => match colors.h2 {
68
-            Some(color) => color,
69
-            None => String::from("#FF1493"),
70
-        },
287
+fn h2_color() -> Option<String> {
288
+    read().colors?.h2
289
+}
290
+
291
+pub fn get_h2_color() -> String {
292
+    match h2_color() {
293
+        Some(color) => color,
71 294
         None => String::from("#FF1493"),
72 295
     }
73 296
 }
74 297
 
75
-pub fn h3_color() -> String {
76
-    match read().colors {
77
-        Some(colors) => match colors.h3 {
78
-            Some(color) => color,
79
-            None => String::from("#87CEFA"),
80
-        },
298
+fn h3_color() -> Option<String> {
299
+    read().colors?.h3
300
+}
301
+
302
+pub fn get_h3_color() -> String {
303
+    match h3_color() {
304
+        Some(color) => color,
81 305
         None => String::from("#87CEFA"),
82 306
     }
83 307
 }
84 308
 
85
-pub fn list_color() -> String {
86
-    match read().colors {
87
-        Some(colors) => match colors.list {
88
-            Some(color) => color,
89
-            None => String::from("green"),
90
-        },
309
+fn list_color() -> Option<String> {
310
+    read().colors?.list
311
+}
312
+
313
+pub fn get_list_color() -> String {
314
+    match list_color() {
315
+        Some(color) => color,
91 316
         None => String::from("green"),
92 317
     }
93 318
 }
94 319
 
95
-pub fn text_color() -> String {
96
-    match read().colors {
97
-        Some(colors) => match colors.text {
98
-            Some(color) => color,
99
-            None => String::from("black"),
100
-        },
320
+fn text_color() -> Option<String> {
321
+    read().colors?.text
322
+}
323
+
324
+pub fn get_text_color() -> String {
325
+    match text_color() {
326
+        Some(color) => color,
101 327
         None => String::from("black"),
102 328
     }
103 329
 }
104 330
 
105 331
 pub fn background_color() -> Option<String> {
106
-    match read().colors {
107
-        Some(colors) => colors.background,
108
-        None => None,
109
-    }
332
+    read().colors?.background
110 333
 }
111 334
 
112
-pub fn h1_character() -> String {
113
-    match read().characters {
114
-        Some(characters) => match characters.h1 {
115
-            Some(character) => character,
116
-            None => String::new(),
117
-        },
118
-        None => String::new(),
119
-    }
335
+fn h1_character() -> Option<String> {
336
+    read().characters?.h1
120 337
 }
121 338
 
122
-pub fn h2_character() -> String {
123
-    match read().characters {
124
-        Some(characters) => match characters.h2 {
125
-            Some(character) => character,
126
-            None => String::new(),
127
-        },
339
+pub fn get_h1_character() -> String {
340
+    match h1_character() {
341
+        Some(char) => char,
128 342
         None => String::new(),
129 343
     }
130 344
 }
131 345
 
132
-pub fn h3_character() -> String {
133
-    match read().characters {
134
-        Some(characters) => match characters.h3 {
135
-            Some(character) => character,
136
-            None => String::new(),
137
-        },
346
+fn h2_character() -> Option<String> {
347
+    read().characters?.h2
348
+}
349
+
350
+pub fn get_h2_character() -> String {
351
+    match h2_character() {
352
+        Some(char) => char,
138 353
         None => String::new(),
139 354
     }
140 355
 }
141 356
 
142
-pub fn list_character() -> String {
143
-    match read().characters {
144
-        Some(characters) => match characters.list {
145
-            Some(character) => character,
146
-            None => String::from("■"),
147
-        },
148
-        None => String::from("■"),
149
-    }
357
+fn h3_character() -> Option<String> {
358
+    read().characters?.h3
150 359
 }
151 360
 
152
-pub fn finger_monospace() -> bool {
153
-    match read().monospace {
154
-        Some(monospace) => match monospace.finger {
155
-            Some(setting) => setting,
156
-            None => true,
157
-        },
158
-        None => true,
361
+pub fn get_h3_character() -> String {
362
+    match h3_character() {
363
+        Some(char) => char,
364
+        None => String::new(),
159 365
     }
160 366
 }
161 367
 
162
-pub fn gemini_monospace() -> bool {
163
-    match read().monospace {
164
-        Some(monospace) => match monospace.gemini {
165
-            Some(setting) => setting,
166
-            None => true,
167
-        },
168
-        None => true,
169
-    }
368
+fn list_character() -> Option<String> {
369
+    read().characters?.list
170 370
 }
171 371
 
172
-pub fn gopher_monospace() -> bool {
173
-    match read().monospace {
174
-        Some(monospace) => match monospace.gopher {
175
-            Some(setting) => setting,
176
-            None => true,
177
-        },
178
-        None => true,
372
+pub fn get_list_character() -> String {
373
+    match list_character() {
374
+        Some(char) => char,
375
+        None => String::from("■"),
179 376
     }
180 377
 }
181 378
 

Loading…
Cancel
Save