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

fmt/color.h missing format_to overload #1593

Closed
Sarcasm opened this issue Mar 14, 2020 · 3 comments
Closed

fmt/color.h missing format_to overload #1593

Sarcasm opened this issue Mar 14, 2020 · 3 comments

Comments

@Sarcasm
Copy link

Sarcasm commented Mar 14, 2020

Hello,

I was wondering if there was any reason for fmt/color.h to not provide a format_to() overload?
I'd like to print messages to stderr using a style similar to GCC/Clang:

  1. subject in bold
  2. diagnostics kind in bold and colored: e.g. red for errors
  3. message in normal text

However, due to multiprocessing issues, I'd like to write the messages "atomically" to stderr so output does not get mixed up.

Right now I can do it that way:

std::string subject = fmt::format(fmt::emphasis::bold, "{}:", p);
std::string error = fmt::format(fg(fmt::color::red) | fmt::emphasis::bold, "error:");
fmt::print(stderr, "{} {} {}\n", subject, error, strerror(errno));

But it bothers me to allocate so many std::string, a color-supporting format_to() would be an improvement.

@vitaut
Copy link
Contributor

vitaut commented Mar 14, 2020

It was proposed before (#1161) but noone was interested enough in implementing it probably because there is little value in optimizing allocations when you are dealing with I/O.

@vitaut
Copy link
Contributor

vitaut commented Mar 14, 2020

PRs are welcome =).

@Sarcasm
Copy link
Author

Sarcasm commented Mar 14, 2020

I see, I missed that ticket when searching.
I saw that there was a vformat_to, so I thought it will be peanuts to add, but I realize now that the signature takes a memory_buffer, not an output iterator.

It would be nice for completeness to have it, but I agree that colors are mostly used when printing to a tty, in which case I doubt the extra strings matter much, at least they do not for my use case.

Closing, I will let a future brave soul do it.

Thank you

@Sarcasm Sarcasm closed this as completed Mar 14, 2020
Naios added a commit to Naios/fmt that referenced this issue Aug 30, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Aug 31, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Aug 31, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Aug 31, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Aug 31, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Aug 31, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Aug 31, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Aug 31, 2020
* Fix variable size basic_memory_buffer colorization
* Rewrite the color unit tests to test the same colors against multiple backends
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Sep 1, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Sep 1, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Sep 1, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Sep 1, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Sep 1, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Sep 4, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
Naios added a commit to Naios/fmt that referenced this issue Sep 4, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref fmtlib#1842
* Ref fmtlib#1593
vitaut pushed a commit that referenced this issue Sep 6, 2020
* Fix variable size basic_memory_buffer colorization
* Fix an unused arguments warning on GCC that blocks the CI otherwise
* Ref #1842
* Ref #1593
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