diff --git a/crates/sss_cli/src/config.rs b/crates/sss_cli/src/config.rs index 486b050..72926f4 100644 --- a/crates/sss_cli/src/config.rs +++ b/crates/sss_cli/src/config.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use clap::Parser; -use merge2::{bool::overwrite_false, Merge}; +use merge2::{bool::overwrite_false, option::recursive, Merge}; use serde::{Deserialize, Serialize}; use sss_lib::{default_bool, swap_option}; @@ -15,7 +15,7 @@ struct ClapConfig { #[merge(skip)] config: Option, #[clap(flatten)] - #[merge(strategy = swap_option)] + #[merge(strategy = recursive)] pub cli: Option, // lib configs #[clap(flatten)] diff --git a/crates/sss_code/src/config.rs b/crates/sss_code/src/config.rs index fa89965..c8f61e2 100644 --- a/crates/sss_code/src/config.rs +++ b/crates/sss_code/src/config.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use clap::Parser; use clap_stdin::FileOrStdin; -use merge2::{bool::overwrite_false, Merge}; +use merge2::{bool::overwrite_false, option::recursive, Merge}; use serde::{Deserialize, Serialize}; use sss_lib::{default_bool, swap_option}; @@ -17,7 +17,7 @@ struct ClapConfig { #[merge(skip)] config: Option, #[clap(flatten)] - #[merge(strategy = swap_option)] + #[merge(strategy = recursive)] pub code: Option, // lib configs #[clap(flatten)] @@ -29,23 +29,24 @@ struct ClapConfig { pub struct CodeConfig { #[clap(help = "Content to take screenshot. It accepts stdin or File")] #[serde(skip)] - #[merge(skip)] + #[merge(strategy = swap_option)] pub content: Option>, #[clap(long, help = "Generate cache of theme and/or syntaxes")] #[serde(skip)] - #[merge(skip)] + #[merge(strategy = swap_option)] pub build_cache: Option, #[clap( long, short, - default_value = "base16-ocean.dark", help = "Theme file to use. May be a path, or an embedded theme. Embedded themes will take precendence." )] + #[merge(strategy = swap_option)] pub theme: Option, #[clap( long, help = "[Not recommended for manual use] Set theme from vim highlights, format: group,bg,fg,style;group,bg,fg,style;" )] + #[merge(strategy = swap_option)] pub vim_theme: Option, // Setting synctect #[clap( @@ -65,6 +66,7 @@ pub struct CodeConfig { long, help = "Additional folder to search for .sublime-syntax files in" )] + #[merge(strategy = swap_option)] pub extra_syntaxes: Option, #[clap(long, short, help = "Set the extension of language input")] #[serde(skip)] @@ -86,7 +88,8 @@ pub struct CodeConfig { #[merge(strategy = overwrite_false)] #[serde(default = "default_bool")] pub line_numbers: bool, - #[clap(long, default_value = "4", help = "Tab width")] + #[clap(long, help = "Tab width")] + #[merge(strategy = swap_option)] pub tab_width: Option, } diff --git a/crates/sss_code/src/img.rs b/crates/sss_code/src/img.rs index 2984181..83ca231 100644 --- a/crates/sss_code/src/img.rs +++ b/crates/sss_code/src/img.rs @@ -157,7 +157,7 @@ impl<'a> DynImageContent for ImageCode<'a> { .background .map(|b| Background::Solid(Rgba([b.r, b.g, b.b, b.a])))) .unwrap(); - let tab = " ".repeat(self.config.tab_width.unwrap() as usize); + let tab = " ".repeat(self.config.tab_width.unwrap_or(4) as usize); let lines = self.content.split('\n').collect::>(); let line_range = self .config diff --git a/crates/sss_code/src/main.rs b/crates/sss_code/src/main.rs index b52e27f..b2fc241 100644 --- a/crates/sss_code/src/main.rs +++ b/crates/sss_code/src/main.rs @@ -98,7 +98,7 @@ fn main() { .themes .get(&theme) .map(Cow::Borrowed) - .unwrap_or_else(|| Cow::Owned(load_theme(&theme, true))) + .unwrap_or_else(|| Cow::Owned(load_theme(&theme, false))) }; if theme.settings.background.is_some() diff --git a/crates/sss_code/src/theme.rs b/crates/sss_code/src/theme.rs index 7f3b88f..ed8aa8d 100644 --- a/crates/sss_code/src/theme.rs +++ b/crates/sss_code/src/theme.rs @@ -24,11 +24,12 @@ pub fn load_theme(tm_file: &str, enable_caching: bool) -> Theme { if tm_cache.exists() { from_dump_file(tm_cache).unwrap() } else { - let theme = ThemeSet::get_theme(tm_path).unwrap(); + let theme = + ThemeSet::get_theme(tm_path).expect(&format!("Theme {tm_path:?} not found")); dump_to_file(&theme, tm_cache).unwrap(); theme } } else { - ThemeSet::get_theme(tm_path).unwrap() + ThemeSet::get_theme(tm_path).expect(&format!("Theme {tm_path:?} not found")) } }