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:
parent
f6cbee9e27
commit
0ebb9cbfe2
34
src/theme.rs
34
src/theme.rs
@ -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>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user