Skip to content

Commit

Permalink
🎨Border color update
Browse files Browse the repository at this point in the history
  • Loading branch information
Serters committed Jan 19, 2025
1 parent 8e2f466 commit b3bb00f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/color_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,23 @@ pub fn update_panel() -> Result<(), Box<dyn Error>> {

fs::write(&panel_path, content)?;
Ok(())
}

pub fn update_border() -> Result<(), Box<dyn Error>> {

let theme_path = config::get_theme_path()?;
let border_color = config::get_base_color()?;

let mut content = fs::read_to_string(&theme_path)?;

let border_re = Regex::new(regex_patterns::PATTERN_BORDER_COLOR)?;

content = border_re
.replace_all(&content, |caps: &regex::Captures| {
caps[0].replace(&caps[1], &border_color)
})
.to_string();

fs::write(&theme_path, content)?;
Ok(())
}
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod utils;
use std::error::Error;
use clap::{Parser, CommandFactory};

use crate::color_updates::{update_search_bar, update_whiskar_menu, update_panel};
use crate::color_updates::{update_search_bar, update_whiskar_menu, update_panel, update_border};
use crate::config::create_default_config;

#[derive(Parser)]
Expand All @@ -27,6 +27,9 @@ struct Cli {

#[arg(long)]
createconfig: bool,

#[arg(long)]
updateborder: bool
}
fn main() -> Result<(), Box<dyn Error>> {
let cli = Cli::parse();
Expand Down Expand Up @@ -54,5 +57,9 @@ fn main() -> Result<(), Box<dyn Error>> {
update_panel()?;
}

if cli.updateall || cli.updateborder {
update_border()?;
}

Ok(())
}
2 changes: 2 additions & 0 deletions src/regex_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ pub const PATTERN_PANEL_BACKGROUND_RGBA: &str = r#"<property name="background-rg
<value type="double" value="([^"]+)"/>\s*
<value type="double" value="([^"]+)"/>\s*
</property>"#;

pub const PATTERN_BORDER_COLOR: &str = r"entry\s*\{\s*border:\s*[^;]+;\s*padding:\s*[^;]+;\s*caret-color:\s*[^;]+;\s*border-radius:\s*[^;]+;\s*transition:\s*[^;]+;\s*color:\s*[^;]+;\s*border-color:\s*([^;]+);\s*background-color:\s*[^;]+;\s*\}";

0 comments on commit b3bb00f

Please sign in to comment.