From 19488dbf915df6b3b9e962ced1f9159894f99e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Tue, 16 Apr 2024 14:43:29 +0200 Subject: [PATCH] Remove HighlightingAssets::default_theme() --- src/assets.rs | 57 --------------------------------------------------- src/theme.rs | 4 +++- 2 files changed, 3 insertions(+), 58 deletions(-) diff --git a/src/assets.rs b/src/assets.rs index 857f416b..d32ccbd4 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -70,43 +70,6 @@ impl HighlightingAssets { } } - /// The default theme. - /// - /// ### Windows and Linux - /// - /// Windows and most Linux distributions has a dark terminal theme by - /// default. On these platforms, this function always returns a theme that - /// looks good on a dark background. - /// - /// ### macOS - /// - /// On macOS the default terminal background is light, but it is common that - /// Dark Mode is active, which makes the terminal background dark. On this - /// platform, the default theme depends on - /// ```bash - /// defaults read -globalDomain AppleInterfaceStyle - /// ``` - /// To avoid the overhead of the check on macOS, simply specify a theme - /// explicitly via `--theme`, `BAT_THEME`, or `~/.config/bat`. - /// - /// See and - /// for more context. - #[deprecated(note = "use bat::theme::theme instead")] - pub fn default_theme() -> &'static str { - #[cfg(not(target_os = "macos"))] - { - default_theme(ColorScheme::Dark) - } - #[cfg(target_os = "macos")] - { - if macos_dark_mode_active() { - default_theme(ColorScheme::Dark) - } else { - default_theme(ColorScheme::Light) - } - } - } - pub fn from_cache(cache_path: &Path) -> Result { Ok(HighlightingAssets::new( SerializedSyntaxSet::FromFile(cache_path.join("syntaxes.bin")), @@ -389,26 +352,6 @@ fn asset_from_cache( .map_err(|_| format!("Could not parse cached {description}").into()) } -#[cfg(target_os = "macos")] -fn macos_dark_mode_active() -> bool { - const PREFERENCES_FILE: &str = "Library/Preferences/.GlobalPreferences.plist"; - const STYLE_KEY: &str = "AppleInterfaceStyle"; - - let preferences_file = home::home_dir() - .map(|home| home.join(PREFERENCES_FILE)) - .expect("Could not get home directory"); - - match plist::Value::from_file(preferences_file).map(|file| file.into_dictionary()) { - Ok(Some(preferences)) => match preferences.get(STYLE_KEY).and_then(|val| val.as_string()) { - Some(value) => value == "Dark", - // If the key does not exist, then light theme is currently in use. - None => false, - }, - // Unreachable, in theory. All macOS users have a home directory and preferences file setup. - Ok(None) | Err(_) => true, - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/theme.rs b/src/theme.rs index ec3e3d34..53477939 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -32,7 +32,9 @@ fn detect(when: DetectColorScheme, detector: &dyn ColorSchemeDetector) -> Option should_detect.then(|| detector.detect()).flatten() } -pub(crate) const fn default_theme(color_scheme: ColorScheme) -> &'static str { +/// The default theme, suitable for the given color scheme. +/// Use [`theme`], if you want to automatically detect the color scheme from the terminal. +pub const fn default_theme(color_scheme: ColorScheme) -> &'static str { match color_scheme { ColorScheme::Dark => "Monokai Extended", ColorScheme::Light => "Monokai Extended Light",