Function owo_colors::with_override

source ยท
pub fn with_override<T, F: FnOnce() -> T>(enabled: bool, f: F) -> T
Expand description

Set an override value for whether or not colors are supported using set_override while executing the closure provided.

Once the function has executed the value will be reset to the previous set (or unset) override.

This is especially useful in use-cases where one would like to temporarily override the supported color set, without impacting previous configurations.

set_override(false);
assert_eq!("example".if_supports_color(Stream::Stdout, |value| value.bg::<Black>()).to_string(), "example");

with_override(true, || {
    assert_eq!("example".if_supports_color(Stream::Stdout, |value| value.bg::<Black>()).to_string(), "\x1b[40mexample\x1b[49m");
});

assert_eq!("example".if_supports_color(Stream::Stdout, |value| value.bg::<Black>()).to_string(), "example");