Skip to content

Commit

Permalink
fix: solve conflicts with merge structs
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Mar 24, 2024
1 parent 7903b2f commit 75379c9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/sss_cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -15,7 +15,7 @@ struct ClapConfig {
#[merge(skip)]
config: Option<PathBuf>,
#[clap(flatten)]
#[merge(strategy = swap_option)]
#[merge(strategy = recursive)]
pub cli: Option<CliConfig>,
// lib configs
#[clap(flatten)]
Expand Down
15 changes: 9 additions & 6 deletions crates/sss_code/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -17,7 +17,7 @@ struct ClapConfig {
#[merge(skip)]
config: Option<PathBuf>,
#[clap(flatten)]
#[merge(strategy = swap_option)]
#[merge(strategy = recursive)]
pub code: Option<CodeConfig>,
// lib configs
#[clap(flatten)]
Expand All @@ -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<FileOrStdin<String>>,
#[clap(long, help = "Generate cache of theme and/or syntaxes")]
#[serde(skip)]
#[merge(skip)]
#[merge(strategy = swap_option)]
pub build_cache: Option<PathBuf>,
#[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<String>,
#[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<String>,
// Setting synctect
#[clap(
Expand All @@ -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<String>,
#[clap(long, short, help = "Set the extension of language input")]
#[serde(skip)]
Expand All @@ -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<u8>,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sss_code/src/img.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<&str>>();
let line_range = self
.config
Expand Down
2 changes: 1 addition & 1 deletion crates/sss_code/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions crates/sss_code/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

0 comments on commit 75379c9

Please sign in to comment.