-- Leo's gemini proxy
-- Connecting to typed-hole.org:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
commit 95f64bf85ee4e59664f07bb4d3707a0b1c5c6e88
Author: Julien Blanchard <julien@typed-hole.org>
Date: Mon Apr 20 14:31:30 2020 +0200
Customize some settings
diff --git a/Cargo.lock b/Cargo.lock
index 4d89443..271648e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -153,7 +153,10 @@ dependencies = [
"pango 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -830,6 +833,21 @@ dependencies = [
]
[[package]]
+name = "serde"
+version = "1.0.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "serde_derive"
+version = "1.0.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -882,6 +900,14 @@ dependencies = [
]
[[package]]
+name = "toml"
+version = "0.5.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "unicode-bidi"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1036,12 +1062,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "87f550b06b6cba9c8b8be3ee73f391990116bf527450d2556e9b9ce263b9a021"
"checksum security-framework 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8ef2429d7cefe5fd28bd1d2ed41c944547d4ff84776f5935b456da44593a16df"
"checksum security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895"
+"checksum serde 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
+"checksum serde_derive 1.0.106 (registry+https://github.com/rust-lang/crates.io-index)" = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecf3b85f68e8abaa7555aa5abdb1153079387e60b718283d732f03897fcfc86"
"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
+"checksum toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
"checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
diff --git a/Cargo.toml b/Cargo.toml
index 3262b65..4a8cfee 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,6 +23,9 @@ dirs = "*"
lazy_static = "*"
ansi-parser = "0.6.5"
percent-encoding="*"
+toml="*"
+serde="*"
+serde_derive="*"
[dependencies.gtk]
version = "0.8.0"
diff --git a/data/castor_settings.toml.example b/data/castor_settings.toml.example
new file mode 100644
index 0000000..42858ef
--- /dev/null
+++ b/data/castor_settings.toml.example
@@ -0,0 +1,10 @@
+[colors]
+h1 = "red"
+h2 = "#FF6347"
+h3 = "green"
+list = "#C71585"
+text = "#FF1493"
+background = "#FFC0CB"
+
+[characters]
+list = "🌼"
diff --git a/src/castor.glade b/src/castor.glade
index 079ec19..7bba5c9 100644
--- a/src/castor.glade
+++ b/src/castor.glade
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.22.2 -->
+<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.16"/>
<object class="GtkTextBuffer"/>
diff --git a/src/main.rs b/src/main.rs
index 21f74d1..3475108 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,6 +29,7 @@ use gemini::link::Link as GeminiLink;
use gopher::link::Link as GopherLink;
mod protocols;
use protocols::{Finger, Gemini, Gopher, Protocol, Scheme};
+mod settings;
mod status;
use status::Status;
@@ -38,6 +39,9 @@ fn main() {
// Create the main window.
let gui = Arc::new(Gui::new());
+ let content_view = gui.content_view();
+ let color = gdk::RGBA::from_str(&settings::background_color()).unwrap();
+ content_view.override_background_color(gtk::StateFlags::NORMAL, Some(&color));
// Bind back button
{
@@ -293,7 +297,9 @@ fn draw_gemini_content(
buffer.insert_markup(
&mut end_iter,
&format!(
- "<span foreground=\"#9932CC\" size=\"x-large\">{}</span>\n",
+ "<span foreground=\"{}\" size=\"x-large\">{}{}</span>\n",
+ settings::h1_color(),
+ settings::h1_character(),
header
),
);
@@ -303,7 +309,9 @@ fn draw_gemini_content(
buffer.insert_markup(
&mut end_iter,
&format!(
- "<span foreground=\"#FF1493\" size=\"large\">{}</span>\n",
+ "<span foreground=\"{}\" size=\"large\">{}{}</span>\n",
+ settings::h2_color(),
+ settings::h2_character(),
header
),
);
@@ -313,7 +321,9 @@ fn draw_gemini_content(
buffer.insert_markup(
&mut end_iter,
&format!(
- "<span foreground=\"#87CEFA\" size=\"medium\">{}</span>\n",
+ "<span foreground=\"{}\" size=\"medium\">{}{}</span>\n",
+ settings::h3_color(),
+ settings::h3_character(),
header
),
);
@@ -322,7 +332,10 @@ fn draw_gemini_content(
let mut end_iter = buffer.get_end_iter();
buffer.insert_markup(
&mut end_iter,
- &format!("<span foreground=\"green\">â– {}</span>\n", item),
+ &format!("<span foreground=\"{}\">{} {}</span>\n",
+ settings::list_color(),
+ settings::list_character(),
+ item),
);
}
Ok(gemini::parser::TextElement::MonoText(_text)) => {
@@ -334,11 +347,15 @@ fn draw_gemini_content(
true => {
buffer.insert_markup(
&mut end_iter,
- &format!("<span font_family=\"monospace\">{}</span>\n", text),
+ &format!("<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
+ settings::text_color(),
+ text),
);
},
false => {
- buffer.insert_markup(&mut end_iter, &format!("{}\n", text));
+ buffer.insert_markup(&mut end_iter, &format!("<span foreground=\"{}\">{}</span>\n",
+ settings::text_color(),
+ text));
}
}
}
@@ -489,6 +506,7 @@ fn insert_gemini_button(gui: &Arc<Gui>, url: Url, label: String) {
let button = gtk::Button::new_with_label(&button_label);
button.set_tooltip_text(Some(&url.to_string()));
+ // button.set_background_color();
button.connect_clicked(clone!(@weak gui => move |_| {
match url.scheme() {
diff --git a/src/settings.rs b/src/settings.rs
new file mode 100644
index 0000000..062108d
--- /dev/null
+++ b/src/settings.rs
@@ -0,0 +1,154 @@
+extern crate dirs;
+
+use std::fs::File;
+use std::fs::OpenOptions;
+use std::io::Read;
+
+use serde_derive::Deserialize;
+
+#[derive(Deserialize)]
+struct Settings {
+ colors: Option<Color>,
+ characters: Option<Character>,
+}
+
+#[derive(Deserialize)]
+struct Color {
+ h1: Option<String>,
+ h2: Option<String>,
+ h3: Option<String>,
+ list: Option<String>,
+ text: Option<String>,
+ background: Option<String>,
+}
+
+#[derive(Deserialize)]
+struct Character {
+ h1: Option<String>,
+ h2: Option<String>,
+ h3: Option<String>,
+ list: Option<String>,
+}
+
+pub fn h1_color() -> String {
+ match read().colors {
+ Some(colors) => match colors.h1 {
+ Some(color) => color,
+ None => String::from("#9932CC")
+ },
+ None => String::from("#9932CC")
+ }
+}
+
+pub fn h2_color() -> String {
+ match read().colors {
+ Some(colors) => match colors.h2 {
+ Some(color) => color,
+ None => String::from("#FF1493")
+ },
+ None => String::from("#FF1493")
+ }
+}
+
+pub fn h3_color() -> String {
+ match read().colors {
+ Some(colors) => match colors.h3 {
+ Some(color) => color,
+ None => String::from("#87CEFA")
+ },
+ None => String::from("#87CEFA")
+ }
+}
+
+pub fn list_color() -> String {
+ match read().colors {
+ Some(colors) => match colors.list {
+ Some(color) => color,
+ None => String::from("green")
+ }
+ None => String::from("green")
+ }
+}
+
+pub fn text_color() -> String {
+ match read().colors {
+ Some(colors) => match colors.text {
+ Some(color) => color,
+ None => String::from("black")
+ }
+ None => String::from("black")
+ }
+}
+
+pub fn background_color() -> String {
+ match read().colors {
+ Some(colors) => match colors.background {
+ Some(color) => color,
+ None => String::from("white")
+ }
+ None => String::from("white")
+ }
+}
+
+pub fn h1_character() -> String {
+ match read().characters {
+ Some(characters) => match characters.h1 {
+ Some(character) => character,
+ None => String::new()
+ }
+ None => String::new()
+ }
+}
+
+pub fn h2_character() -> String {
+ match read().characters {
+ Some(characters) => match characters.h2 {
+ Some(character) => character,
+ None => String::new()
+ }
+ None => String::new()
+ }
+}
+
+pub fn h3_character() -> String {
+ match read().characters {
+ Some(characters) => match characters.h3 {
+ Some(character) => character,
+ None => String::new()
+ }
+ None => String::new()
+ }
+}
+
+pub fn list_character() -> String {
+ match read().characters {
+ Some(characters) => match characters.list {
+ Some(character) => character,
+ None => String::from("â– ")
+ }
+ None => String::from("â– ")
+ }
+}
+
+fn read() -> Settings {
+ let mut file = settings_file();
+ let mut content = String::new();
+ file.read_to_string(&mut content)
+ .expect("Unable to read file");
+
+ let settings: Settings = toml::from_str(&content).unwrap();
+ settings
+}
+
+fn settings_file() -> File {
+ let mut bookmarks = dirs::data_local_dir().unwrap();
+ bookmarks.push("castor_settings.toml");
+ let file_path = bookmarks.into_os_string();
+
+ OpenOptions::new()
+ .create(true)
+ .append(true)
+ .read(true)
+ .open(file_path)
+ .expect("file not found")
+}
---
Served by Pollux Gemini Server.
-- Response ended
-- Page fetched on Sun May 19 04:24:48 2024