diff --git a/include/fmt/color.h b/include/fmt/color.h index b94e8ed4..b69c1488 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -409,13 +409,16 @@ template struct ansi_color_escape { if (has_emphasis(em, emphasis::conceal)) em_codes[6] = 8; if (has_emphasis(em, emphasis::strikethrough)) em_codes[7] = 9; + buffer[size++] = static_cast('\x1b'); + buffer[size++] = static_cast('['); + for (size_t i = 0; i < num_emphases; ++i) { if (!em_codes[i]) continue; - buffer[size++] = static_cast('\x1b'); - buffer[size++] = static_cast('['); buffer[size++] = static_cast('0' + em_codes[i]); - buffer[size++] = static_cast('m'); + buffer[size++] = static_cast(';'); } + + buffer[size - 1] = static_cast('m'); } FMT_CONSTEXPR operator const Char*() const noexcept { return buffer; } diff --git a/test/color-test.cc b/test/color-test.cc index 86faca9d..45d8cd92 100644 --- a/test/color-test.cc +++ b/test/color-test.cc @@ -121,7 +121,7 @@ TEST(color_test, format) { fmt::emphasis::underline | fmt::emphasis::blink | fmt::emphasis::reverse | fmt::emphasis::conceal | fmt::emphasis::strikethrough)), - "\x1b[1m\x1b[2m\x1b[3m\x1b[4m\x1b[5m\x1b[7m\x1b[8m\x1b[9mall\x1b[0m"); + "\x1b[1;2;3;4;5;7;8;9mall\x1b[0m"); } TEST(color_test, format_to) {