Support color printing strings with zero bytes

This is a clean up after #1351.
This commit is contained in:
Orivej Desh 2019-10-10 21:51:43 +00:00
parent 96f91428c6
commit 7fd7ef32c2
2 changed files with 3 additions and 2 deletions

View File

@ -503,8 +503,7 @@ void vprint(std::FILE* f, const text_style& ts, const S& format,
basic_format_args<buffer_context<Char> > args) {
basic_memory_buffer<Char> buf;
internal::vformat_to(buf, ts, to_string_view(format), args);
buf.push_back(Char(0));
internal::fputs(buf.data(), f);
std::fwrite(buf.data(), 1, buf.size(), f);
}
/**

View File

@ -45,6 +45,8 @@ TEST(ColorsTest, ColorsPrint) {
EXPECT_WRITE(stdout,
fmt::print(bg(fmt::terminal_color::bright_magenta), "tbmagenta"),
"\x1b[105mtbmagenta\x1b[0m");
EXPECT_WRITE(stdout, fmt::print(fmt::emphasis::bold, "{}", std::string("a\0b", 3)),
std::string("\x1b[1ma\0b\x1b[0m", 11));
}
TEST(ColorsTest, Format) {