Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] introspection if colors are supported #87

Open
indietyp opened this issue Jan 10, 2023 · 1 comment
Open

[Feature Request] introspection if colors are supported #87

indietyp opened this issue Jan 10, 2023 · 1 comment

Comments

@indietyp
Copy link
Contributor

Ability to introspect the current override status.

(follow-up to #84)

Currently, one is already able to determine if colors are supported, but only through a "hack" what I'd like is a new function:

supports_color considers the override value and (might ?) mirror the API of the underlying supports-color crate. This is especially useful in cases where one would A) like to query the negative status, e.g. do something if colors are not supported and B) get more information, e.g. only execute X if truecolor is supported, but still take into account the globally set override.

What do you think? I'd be happy to draft up a PR and implement the functionality, but before that would like to know if this is something that the library should support.

How to currently get the status (sadly involves additional atomics, is cumbersome and requires alloc):

let supports_color = AtomicBool::new(false);
owo_colors::set_override(true);
format!("{}", x.if_supports_color(Stream::Stdout, |x| {
    supports_color.store(true, core::sync::atomic::Ordering::SeqCst);
    x
}));
supports_color.load(core::sync::atomic::Ordering::SeqCst)
@indietyp indietyp changed the title [Feature Request] [Feature Request] introspection if colors are supported Jan 10, 2023
@charliermarsh
Copy link

I would also find this useful coming from colored (which exposes should_colorize).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants