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

add disable_colors #3918

Closed
wants to merge 5 commits into from
Closed

add disable_colors #3918

wants to merge 5 commits into from

Conversation

Toni500github
Copy link

@Toni500github Toni500github commented Apr 3, 2024

disable_colors is just a normal bool which the dev or the user can decide in the program if disable the printing of colors or not.

an example:

#include <fmt/color.h>

int main() {
  // prints "Hello" in red fg
  fmt::print(fg(fmt::terminal_color::red), "Hello\n");
  // let's disable all colors prints
  fmt::disable_colors = true;
  // prints "Hello" in blank color
  fmt::print(fg(fmt::terminal_color::red), "Hello\n");
}

this can be also useful in cases where the user has the enviroment variable NO_COLOR set (https://no-color.org).
another example:

#include <fmt/color.h>

int main() {
    char *no_color = getenv("NO_COLOR");

    // prints "Hello" in red fg
    fmt::print(fg(fmt::terminal_color::red), "Hello\n");
    
    if (no_color != NULL && no_color[0] != '\0')
        fmt::disable_colors = true;

    // will prints "Hello" in blank color if we have $NO_COLOR set, else it will print it in red
    fmt::print(fg(fmt::terminal_color::red), "Hello\n");
}

Fixes #2137

@Toni500github
Copy link
Author

if needs any changes just let me know

Toni500github added a commit to BurntRanch/TabAUR that referenced this pull request Apr 3, 2024
@vitaut
Copy link
Contributor

vitaut commented Apr 3, 2024

Thanks for the PR but I don't think it's a good idea to introduce global state like this. You can write your own wrapper function that does this.

@vitaut vitaut closed this Apr 3, 2024
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

Successfully merging this pull request may close these issues.

Provide a mechanism to disable color formatting globally
2 participants