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

RGB print support for {fmt} #762

Closed
Remotion opened this issue Jun 6, 2018 · 3 comments
Closed

RGB print support for {fmt} #762

Remotion opened this issue Jun 6, 2018 · 3 comments

Comments

@Remotion
Copy link
Contributor

Remotion commented Jun 6, 2018

What do you think about this RGB print support?
https://github.com/Remotion/fmt_extension/blob/develop/include/fmt_rgb.h

fmt::print(fmt::rgb(120,55,220), "some colored  text");

fmt::print(fmt::AliceBlue, "some colored text");

This also work on Windows 10 too.

@eliaskosunen
Copy link
Contributor

eliaskosunen commented Jun 6, 2018

There's (v)print_colored already:

fmt/include/fmt/core.h

Lines 1167 to 1188 in dd1a5ef

enum color { black, red, green, yellow, blue, magenta, cyan, white };
FMT_API void vprint_colored(color c, string_view format, format_args args);
FMT_API void vprint_colored(color c, wstring_view format, wformat_args args);
/**
Formats a string and prints it to stdout using ANSI escape sequences to
specify color (experimental).
Example:
fmt::print_colored(fmt::RED, "Elapsed time: {0:.2f} seconds", 1.23);
*/
template <typename... Args>
inline void print_colored(color c, string_view format_str,
const Args & ... args) {
vprint_colored(c, format_str, make_format_args(args...));
}
template <typename... Args>
inline void print_colored(color c, wstring_view format_str,
const Args & ... args) {
vprint_colored(c, format_str, make_format_args<wformat_context>(args...));
}
although it's not documented anywhere and the comments deem it as experimental.

@Remotion
Copy link
Contributor Author

Remotion commented Jun 6, 2018

Yes I know this, but it does support only 8 colors and not full RGB.

Also writing fmt::print_colored(fmt::rgb(120,55,220), "some colored text"); is too long without any benefit.

@vitaut
Copy link
Contributor

vitaut commented Jun 7, 2018

What do you think about this RGB print support?

I think it can be useful and, as @eliaskosunen already pointed out, there is a limited support for this already. PRs to extend this functionality are welcome.

Also writing fmt::print_colored(fmt::rgb(120,55,220), "some colored text"); is too long without any benefit.

You are probably right, overloading fmt::print should be harmless provided that there are no undesirable conversions to rgb.

@vitaut vitaut closed this as completed Jun 9, 2018
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

3 participants