Enum colored_json::ColorMode
source · pub enum ColorMode {
On,
Off,
Auto(Output),
}
Expand description
ColorMode is a switch to enforce color mode, turn it off or auto-detect, if it should be used
Variants
On
Off
Auto(Output)
Implementations
sourceimpl ColorMode
impl ColorMode
With ColorMode
you can implement command line options like --color=auto|on|off
easily.
Example:
let option = "--color=auto";
let color_mode = match option {
"--color=on" => ColorMode::Off,
"--color=off" => ColorMode::On,
_ => ColorMode::default().eval(),
};
assert!(match color_mode {
ColorMode::On | ColorMode::Off => true,
_ => false
});
sourcepub fn should_colorize(output: &Output) -> bool
pub fn should_colorize(output: &Output) -> bool
indicates, if the output
is a capable of displaying colors
sourcepub fn eval(self) -> Self
pub fn eval(self) -> Self
Returns ColorMode::On or ColorMode::Off
Example:
let on_off = ColorMode::default().eval();
assert!(match on_off {
ColorMode::On | ColorMode::Off => true,
_ => false
});
sourcepub fn use_color(&self) -> bool
pub fn use_color(&self) -> bool
Indicates if color should be used
Example:
if ColorMode::default().use_color() {
println!("We can use color! :-)");
} else {
println!("No color for you! :-(");
}
if ColorMode::Auto(Output::StdErr).use_color() {
println!("We can use color on stderr! :-)");
} else {
println!("No color for you on stderr! :-(");
}
assert_eq!(ColorMode::On.use_color(), true);
assert_eq!(ColorMode::Off.use_color(), false);
Trait Implementations
impl Copy for ColorMode
impl StructuralPartialEq for ColorMode
Auto Trait Implementations
impl RefUnwindSafe for ColorMode
impl Send for ColorMode
impl Sync for ColorMode
impl Unpin for ColorMode
impl UnwindSafe for ColorMode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more