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: fmt::format_to not implemented for fmt::text_style #1842

Closed
Naios opened this issue Aug 30, 2020 · 2 comments
Closed

fmt/color.h: fmt::format_to not implemented for fmt::text_style #1842

Naios opened this issue Aug 30, 2020 · 2 comments

Comments

@Naios
Copy link
Contributor

Naios commented Aug 30, 2020

e66ba16

Currently it is not possible to format a colorized string to a fmt::memory_buffer using fmt::format_to(memory_buffer, fmt::text_style(... or through any other function because the overload is missing.

It would be great if the missing overload for fmt::format_to(memory_buffer, fmt::text_style could be added.

Overall the color API is inconsistent with the format API and not all format functions support a fmt::text_style overload. Maybe the color API could be aligned in general with the format API.

@Andersama
Copy link

I also just ran into this issue. My work around though not completely templated looks like this:

template <size_t N> struct ansi_esc_sequence {
	uint8_t tail;
	uint8_t opts[N];
};

template <size_t N> struct fmt::formatter<ansi_esc_sequence<N>> : public fmt::formatter<string_view> {
	template <typename FormatContext>
	auto format(const ansi_esc_sequence<N>& p, FormatContext& ctx) noexcept {
		if constexpr (N > 0) {
			return fmt::format_to(ctx.out(), "\033[{}{}"sv, fmt::join(&p.opts[0], &p.opts[0] + N, ";"),
				(char)p.tail);
		}
		else {
			return fmt::format_to(ctx.out(), "\033[{}"sv, (char)p.tail);
		}
	}
};

It's a bit of a pain to specify the colors w/ the ansi sequence this way, definitely in full agreement it was strange to try to avoid this by using color.h only to find format_to wasn't implemented.

@vitaut
Copy link
Contributor

vitaut commented Aug 30, 2020

The color API is for terminal output thus it supports only a subset of functions.

@vitaut vitaut closed this as completed Aug 30, 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
Projects
None yet
Development

No branches or pull requests

3 participants