~julienxx/castor

ec77c753e86074f9b540b0f41cfbec527b17ef0a — Julien Blanchard a month ago 5db06df master 0.9.0
Update defaults and example settings
3 files changed, 58 insertions(+), 45 deletions(-)

R data/{castor_settings.toml.example => settings.toml}
M src/main.rs
M src/settings.rs
R data/castor_settings.toml.example => data/settings.toml +6 -6
@@ 6,14 6,14 @@ max_width = 200
h1 = "red"
h2 = "#FF6347"
h3 = "green"
list = "#C71585"
text = "#FF1493"
background = "#FFC0CB"
list = "#4c4c4c"
text = "#282828"
background = "#f0efee"
[colors.quote]
    foreground="#e4e4e4"
    background="grey"

[characters]
h1 = ">"
h2 = "))"
h3 = "}}}"
list = "🌼 "

[fonts]

M src/main.rs => src/main.rs +13 -15
@@ 39,18 39,17 @@ fn main() {
    let gui = Arc::new(Gui::new());

    // Set background color
    if let Some(color) = settings::background_color() {
        let provider = gtk::CssProvider::new();
        provider
            .load_from_data(format!("textview text {{ background-color: {}; }}", color).as_bytes())
            .expect("Failed to load CSS");

        gtk::StyleContext::add_provider_for_screen(
            &gdk::Screen::get_default().expect("Error initializing gtk css provider."),
            &provider,
            gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
        );
    }
    let color = settings::get_background_color();
    let provider = gtk::CssProvider::new();
    provider
        .load_from_data(format!("textview text {{ background-color: {}; }}", color).as_bytes())
        .expect("Failed to load CSS");

    gtk::StyleContext::add_provider_for_screen(
        &gdk::Screen::get_default().expect("Error initializing gtk css provider."),
        &provider,
        gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
    );

    // Bind back button
    {


@@ 124,9 123,8 @@ fn main() {
    match args.len() {
        // no argument passed, check settings
        1 => {
            if let Some(url) = settings::start_url() {
                route_url(&gui, url)
            }
            let url = settings::get_start_url();
            route_url(&gui, url)
        }
        // Use argument as initial URL
        _ => route_url(&gui, args[1].to_string()),

M src/settings.rs => src/settings.rs +39 -24
@@ 70,10 70,14 @@ struct QuoteColor {
    background: Option<String>,
}

pub fn start_url() -> Option<String> {
    match read().general {
        Some(general) => general.start_url,
        None => None,
fn start_url() -> Option<String> {
    read().general?.start_url
}

pub fn get_start_url() -> String {
    match start_url() {
        Some(url) => url,
        None => "gemini://gemini.circumlunar.space/".to_string(),
    }
}



@@ 84,8 88,12 @@ pub fn max_width() -> Option<usize> {
    }
}

const DEFAULT_FONT: &str = "serif";
const DEFAULT_FONT_STYLE: &str = "normal";
const FONT_SERIF: &str = "serif";
const FONT_MONO: &str = "monospace";
const FONT_SANS: &str = "sans";
const NORMAL_FONT_STYLE: &str = "normal";
const OBLIQUE_FONT_STYLE: &str = "oblique";
const ITALIC_FONT_STYLE: &str = "italic";
const DEFAULT_FONT_SIZE: i32 = 11 * pango_sys::PANGO_SCALE;
const DEFAULT_H1_FONT_SIZE: i32 = 16 * pango_sys::PANGO_SCALE;
const DEFAULT_H2_FONT_SIZE: i32 = 13 * pango_sys::PANGO_SCALE;


@@ 102,7 110,7 @@ fn finger_font_size() -> Option<i32> {
pub fn get_finger_font_family() -> String {
    match finger_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_MONO),
    }
}



@@ 120,7 128,7 @@ fn gemini_text_font_family() -> Option<String> {
pub fn get_gemini_text_font_family() -> String {
    match gemini_text_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_SERIF),
    }
}



@@ 157,14 165,14 @@ pub fn get_gemini_h1_font_size() -> i32 {
pub fn get_gemini_h1_font_family() -> String {
    match gemini_h1_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_SERIF),
    }
}

pub fn get_gemini_h1_font_style() -> String {
    match gemini_h1_font_style() {
        Some(style) => style,
        None => String::from(DEFAULT_FONT_STYLE),
        None => String::from(NORMAL_FONT_STYLE),
    }
}



@@ 190,14 198,14 @@ pub fn get_gemini_h2_font_size() -> i32 {
pub fn get_gemini_h2_font_family() -> String {
    match gemini_h2_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_SERIF),
    }
}

pub fn get_gemini_h2_font_style() -> String {
    match gemini_h2_font_style() {
        Some(style) => style,
        None => String::from(DEFAULT_FONT_STYLE),
        None => String::from(OBLIQUE_FONT_STYLE),
    }
}



@@ 223,14 231,14 @@ pub fn get_gemini_h3_font_size() -> i32 {
pub fn get_gemini_h3_font_family() -> String {
    match gemini_h3_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_SERIF),
    }
}

pub fn get_gemini_h3_font_style() -> String {
    match gemini_h3_font_style() {
        Some(style) => style,
        None => String::from(DEFAULT_FONT_STYLE),
        None => String::from(NORMAL_FONT_STYLE),
    }
}



@@ 268,14 276,14 @@ pub fn get_gemini_list_font_size() -> i32 {
pub fn get_gemini_list_font_family() -> String {
    match gemini_list_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_SANS),
    }
}

pub fn get_gemini_list_font_style() -> String {
    match gemini_list_font_style() {
        Some(style) => style,
        None => String::from(DEFAULT_FONT_STYLE),
        None => String::from(ITALIC_FONT_STYLE),
    }
}



@@ 289,7 297,7 @@ pub fn get_gemini_quote_font_size() -> i32 {
pub fn get_gemini_quote_font_family() -> String {
    match gemini_quote_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_SERIF),
    }
}



@@ 311,7 319,7 @@ fn gopher_font_size() -> Option<i32> {
pub fn get_gopher_font_family() -> String {
    match gopher_font_family() {
        Some(family) => family,
        None => String::from(DEFAULT_FONT),
        None => String::from(FONT_MONO),
    }
}



@@ 329,7 337,7 @@ fn h1_color() -> Option<String> {
pub fn get_h1_color() -> String {
    match h1_color() {
        Some(color) => color,
        None => String::from("#9932CC"),
        None => String::from("red"),
    }
}



@@ 340,7 348,7 @@ fn h2_color() -> Option<String> {
pub fn get_h2_color() -> String {
    match h2_color() {
        Some(color) => color,
        None => String::from("#FF1493"),
        None => String::from("#FF6347"),
    }
}



@@ 351,7 359,7 @@ fn h3_color() -> Option<String> {
pub fn get_h3_color() -> String {
    match h3_color() {
        Some(color) => color,
        None => String::from("#87CEFA"),
        None => String::from("green"),
    }
}



@@ 362,7 370,7 @@ fn list_color() -> Option<String> {
pub fn get_list_color() -> String {
    match list_color() {
        Some(color) => color,
        None => String::from("green"),
        None => String::from("#4c4c4c"),
    }
}



@@ 397,7 405,7 @@ fn text_color() -> Option<String> {
pub fn get_text_color() -> String {
    match text_color() {
        Some(color) => color,
        None => String::from("black"),
        None => String::from("#282828"),
    }
}



@@ 405,6 413,13 @@ pub fn background_color() -> Option<String> {
    read().colors?.background
}

pub fn get_background_color() -> String {
    match background_color() {
        Some(color) => color,
        None => String::from("#f0efee"),
    }
}

fn h1_character() -> Option<String> {
    read().characters?.h1
}


@@ 445,7 460,7 @@ fn list_character() -> Option<String> {
pub fn get_list_character() -> String {
    match list_character() {
        Some(char) => char,
        None => String::from("■"),
        None => String::from("🌼 "),
    }
}