Skip to content

Commit

Permalink
Support color-printing strings with zero bytes
Browse files Browse the repository at this point in the history
This is a clean up after fmtlib#1351.
  • Loading branch information
orivej committed Oct 10, 2019
1 parent a82c1dc commit 3240a66
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions include/fmt/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ void vprint(std::FILE* f, const text_style& ts, const S& format,
if (has_style) {
internal::reset_color<Char>(buf);
}
buf.push_back(Char(0));
internal::fputs(buf.data(), f);
std::fwrite(buf.data(), 1, buf.size(), f);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/color-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3240a66

Please sign in to comment.