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

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
});

indicates, if the output is a capable of displaying colors

Returns ColorMode::On or ColorMode::Off

Example:
let on_off = ColorMode::default().eval();

assert!(match on_off {
    ColorMode::On | ColorMode::Off => true,
    _ => false
});

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

returns ColorMode::Auto(Output::StdOut)

This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.