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

Color formatting doesn't work for wide strings #1594

Closed
Spirrwell opened this issue Mar 15, 2020 · 1 comment
Closed

Color formatting doesn't work for wide strings #1594

Spirrwell opened this issue Mar 15, 2020 · 1 comment

Comments

@Spirrwell
Copy link
Contributor

Hello there!

I don't know if wide strings are intended to not be supported by color formatting, but it seems like a bug.

To put simply, this does not work:

fmt::print( fmt::fg( fmt::color::red ), L"This is a wide formatted string\n" );

If you look at this line here: https://github.com/fmtlib/fmt/blob/master/include/fmt/color.h#L415

It uses std::strlen and if you try to format a wide string with this, it fails to compile as std::strlen assumes 'char' is the type.

I've tried replacing it with this:

return buffer + std::char_traits<Char>::length(buffer);

This seems to work just fine for me. But I haven't done a whole lot of testing.

@vitaut
Copy link
Contributor

vitaut commented Mar 15, 2020

Thanks for reporting. Could you submit a PR with your suggested fix and a test in test/color-test.cc?

Spirrwell added a commit to Spirrwell/fmt that referenced this issue Mar 16, 2020
vitaut pushed a commit that referenced this issue Mar 17, 2020
* Use std::char_traits::length for ansi_color_escape::begin

-Fixes issue #1594 #1594
@vitaut vitaut closed this as completed Mar 17, 2020
chenyt9 pushed a commit to MotorolaMobilityLLC/external-fmtlib that referenced this issue May 9, 2023
* Use std::char_traits::length for ansi_color_escape::beGin

-Fixes issue #1594 fmtlib/fmt#1594
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