fmtlib / fmt

A modern formatting library
https://fmt.dev
Other
19.9k stars 2.43k forks source link

fmt::styled and fmt::formatter<std::string> parse deactivate colors/termaps #3932

Closed GuillaumeDua closed 3 months ago

GuillaumeDua commented 3 months ago

Reproduction: https://godbolt.org/z/o5saW68cq

Here, using any format of the std::string formatter (but the default) results in deactivating the colors/termcaps.

-> Is it the intended behaviour ?

auto str = fmt::format(
    "styled [{0:.2f}]",
    fmt::styled(1.23, fmt::fg(fmt::color::green) | fmt::bg(fmt::color::blue))
);
fmt::print("{}\n", str);

fmt::print("hello {:?} world\n", str);
fmt::print("hello {:?} world\n", std::string{"funny"});
fmt::print("hello \"{}\" world\n", str);
fmt::print("hello ||{:^.20}|| world\n", str);

image

vitaut commented 3 months ago

String formatter doesn't know about ANSI escape codes so it is expected that applying escaping or truncation can interfere with those codes.