~julienxx/castor

Add max_width setting v1 APPLIED

mira: 1
 Add max_width setting

 4 files changed, 12 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~julienxx/castor/patches/11463/mbox | git am -3
Learn more about email & git

[PATCH] Add max_width setting Export this patch

Hi,

I personally dislike adjusting the window size to avoid too long lines,
so I wrote a small patch to add a new setting for that. Hopefully it's
useful!

-mira

---
 README.md                         | 1 +
 data/castor_settings.toml.example | 1 +
 src/draw.rs                       | 3 ++-
 src/settings.rs                   | 8 ++++++++
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d201aff..f04ae48 100644
--- a/README.md
+++ b/README.md
@@ -69,6 +69,7 @@ These are the keys currently supported, you can use hex codes, plain colors name
```
[general]
start_url = "gemini://gemini.circumlunar.space/capcom"
max_width = 200

[colors]
h1 = "red"
diff --git a/data/castor_settings.toml.example b/data/castor_settings.toml.example
index 28b5243..7136157 100644
--- a/data/castor_settings.toml.example
+++ b/data/castor_settings.toml.example
@@ -1,5 +1,6 @@
[general]
start_url = "gemini://gemini.circumlunar.space/capcom"
max_width = 200

[colors]
h1 = "red"
diff --git a/src/draw.rs b/src/draw.rs
index 560a730..ba192a8 100644
--- a/src/draw.rs
+++ b/src/draw.rs
@@ -454,5 +454,6 @@ fn mono_span(text: String) -> String {

fn width(gui: &Arc<Gui>) -> usize {
    let (win_width, _) = gtk::ApplicationWindow::get_size(gui.window());
    (win_width / 10).try_into().unwrap()
    let calculated_width = (win_width / 10).try_into().unwrap();
    std::cmp::min(calculated_width, crate::settings::max_width().unwrap_or(std::usize::MAX))
}
diff --git a/src/settings.rs b/src/settings.rs
index fbbef06..ee226e3 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -18,6 +18,7 @@ struct Settings {
#[derive(Deserialize)]
struct General {
    start_url: Option<String>,
    max_width: Option<usize>,
}

#[derive(Deserialize)]
@@ -76,6 +77,13 @@ pub fn start_url() -> Option<String> {
    }
}

pub fn max_width() -> Option<usize> {
    match read().general {
        Some(general) => general.max_width,
        None => None,
    }
}

const DEFAULT_FONT: &str = "serif";
const DEFAULT_FONT_STYLE: &str = "normal";
const DEFAULT_FONT_SIZE: i32 = 11 * pango_sys::PANGO_SCALE;
-- 
2.27.0
Thanks a lot!