-
Notifications
You must be signed in to change notification settings - Fork 1.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
Color the dbg!()
macro
#3679
Comments
This will probably not happen as The most plausible design I could see would be to add a format specifier for color (adding new macros would require adding An open question would be where to put the common logic of 'if stdout().is_terminal() { /* color / } else { / no color */ } Ultimately I don't think |
I think this could be done without adding coloring to libstd. Instead, libstd could expose a hook for crates to postprocess dbg's output or hook into formatting it does. For example: std::fmt::set_dbg_hook(color_formatter_function) |
I found that you can do struct Struct {
field1: String,
} Perhaps one could dig into the source code of markdown and just impl it the same way? Or perhaps this crate may be used? (I haven't checked yet if they implemented this feature but they might have) |
@amab8901 The issue isn't how to add color to libstd, but that it's a burden for libstd to carry this functionality, for all platforms current and future, maintained forever, and adding overhead to every Rust executable. Additions to libstd are very costly. |
I found this cool crate that offers a colored version of dbg!() called color!().
Unfortunately, it doesn't integrate with all other crates because most people aren't aware of this crate so they haven't added an integration for it. And orphan rule doesn't let me easily create a custom impl for those crates.
Would be really nice if we had colored
dbg!()
output in thedbg!()
macro (or perhaps create another macro for colored debug output, or viaprintln!()
, or something like that). It's especially helpful when dealing with complex nested structs by letting me find what I'm looking for more easily/conveniently.This proposal received lots of positive feedback in the internals forum, so I'm copying it over to this RFC.
The text was updated successfully, but these errors were encountered: