1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-01-19 04:21:06 +00:00

Add Display impl

This commit is contained in:
Tau Gärtli 2024-09-07 21:57:27 +02:00
parent f6cbee9e27
commit 0ebb9cbfe2
No known key found for this signature in database

View File

@ -105,6 +105,20 @@ impl FromStr for ThemePreference {
} }
} }
impl fmt::Display for ThemePreference {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use ThemePreference::*;
match self {
Auto(DetectColorScheme::Auto) => f.write_str("auto"),
Auto(DetectColorScheme::Always) => f.write_str("auto:always"),
Auto(DetectColorScheme::System) => f.write_str("auto:system"),
Fixed(theme) => theme.fmt(f),
Dark => f.write_str("dark"),
Light => f.write_str("light"),
}
}
}
/// The name of a theme or the default theme. /// The name of a theme or the default theme.
/// ///
/// ``` /// ```
@ -478,6 +492,26 @@ mod tests {
} }
} }
mod theme_preference {
use super::*;
#[test]
fn values_roundtrip_via_display() {
let prefs = [
ThemePreference::Auto(DetectColorScheme::Auto),
ThemePreference::Auto(DetectColorScheme::Always),
ThemePreference::Auto(DetectColorScheme::System),
ThemePreference::Fixed(ThemeName::Default),
ThemePreference::Fixed(ThemeName::new("foo")),
ThemePreference::Dark,
ThemePreference::Light,
];
for pref in prefs {
assert_eq!(pref, ThemePreference::new(&pref.to_string()));
}
}
}
struct DetectorStub { struct DetectorStub {
should_detect: bool, should_detect: bool,
color_scheme: Option<ColorScheme>, color_scheme: Option<ColorScheme>,