-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Provide a mechanism to disable color formatting globally #2137
Comments
You can try do something like this to force win console in appropriate mode somewhere in the beginning of your code:
In MinGW it working. |
That's a useful workaround, though I'll still need a way to disable color for file output, etc. I'll see about enabling this workaround in my app, but long term -- is this something that fmtlib could do automatically? It'd be great if this worked out-of-the-box. |
Thanks for the suggestion. I don't think that {fmt} should provide a mechanism to suppress color output based on the global state but you can easily write a formatting function that does this: #include <fmt/color.h>
bool disable_color = false;
template <typename... Args>
void myprint(const fmt::text_style& ts, const Args&... args) {
fmt::print(disable_color ? fmt::text_style() : ts, args...);
}
int main() {
myprint(fg(fmt::terminal_color::red), "Hello\n");
disable_color = true;
myprint(fg(fmt::terminal_color::red), "Hello\n");
} Godbolt: https://godbolt.org/z/bczTor Additionally, it would be nice to fix color formatting on Windows and/or provide an API that enables ANSI escape sequences (basically what @nenin-sc suggested). PRs would be welcome =). |
Fair enough :) I'll probably just disable color on |
Using own wrappers might be a solution if one is using |
It would be nice to disable text styles globally. Ideally, both:
Some terminals (MSVC dev terminals are a glaring example) can't handle the formatting markup, and produce unreadable output when formatting is used (#1794).
#1549 suggests a way to implement this by placing special logic at every call into fmtlib, but this is burdensome and error prone. Having a library-wide solution for this problem would be fantastic.
If there's already a good workaround for this, please let me know. I found some closed issues that were related, but nothing that quite does what I'm looking for here.
The text was updated successfully, but these errors were encountered: