From a190932e8e66b729c15ffaf276a3f38f2883e0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Tue, 16 Apr 2024 14:43:20 +0200 Subject: [PATCH] Use `default_theme()` function from theme module --- src/assets.rs | 27 ++++++++------------------- src/theme.rs | 2 +- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index 53414366..857f416b 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -13,6 +13,7 @@ use crate::error::*; use crate::input::{InputReader, OpenedInput}; use crate::syntax_mapping::ignored_suffixes::IgnoredSuffixes; use crate::syntax_mapping::MappingTarget; +use crate::theme::{default_theme, ColorScheme}; use crate::{bat_warning, SyntaxMapping}; use lazy_theme_set::LazyThemeSet; @@ -94,33 +95,18 @@ impl HighlightingAssets { pub fn default_theme() -> &'static str { #[cfg(not(target_os = "macos"))] { - Self::default_dark_theme() + default_theme(ColorScheme::Dark) } #[cfg(target_os = "macos")] { if macos_dark_mode_active() { - Self::default_dark_theme() + default_theme(ColorScheme::Dark) } else { - Self::default_light_theme() + default_theme(ColorScheme::Light) } } } - /** - * The default theme that looks good on a dark background. - */ - fn default_dark_theme() -> &'static str { - "Monokai Extended" - } - - /** - * The default theme that looks good on a light background. - */ - #[cfg(target_os = "macos")] - fn default_light_theme() -> &'static str { - "Monokai Extended Light" - } - pub fn from_cache(cache_path: &Path) -> Result { Ok(HighlightingAssets::new( SerializedSyntaxSet::FromFile(cache_path.join("syntaxes.bin")), @@ -249,7 +235,10 @@ impl HighlightingAssets { bat_warning!("Unknown theme '{}', using default.", theme) } self.get_theme_set() - .get(self.fallback_theme.unwrap_or_else(Self::default_theme)) + .get( + self.fallback_theme + .unwrap_or_else(|| default_theme(ColorScheme::Dark)), + ) .expect("something is very wrong if the default theme is missing") } } diff --git a/src/theme.rs b/src/theme.rs index b1607140..8ce75e1f 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -32,7 +32,7 @@ fn detect(when: DetectColorScheme, detector: &dyn ColorSchemeDetector) -> Option should_detect.then(|| detector.detect()).flatten() } -const fn default_theme(color_scheme: ColorScheme) -> &'static str { +pub(crate) const fn default_theme(color_scheme: ColorScheme) -> &'static str { match color_scheme { ColorScheme::Dark => "Monokai Extended", ColorScheme::Light => "Monokai Extended Light",