Skip to content

Commit 4dc471f

Browse files
committed
Support color printing strings with zero bytes
This is a clean up after #1351.
1 parent a82c1dc commit 4dc471f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

include/fmt/color.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ void vprint(std::FILE* f, const text_style& ts, const S& format,
526526
if (has_style) {
527527
internal::reset_color<Char>(buf);
528528
}
529-
buf.push_back(Char(0));
530-
internal::fputs(buf.data(), f);
529+
std::fwrite(buf.data(), 1, buf.size(), f);
531530
}
532531

533532
/**

test/color-test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ TEST(ColorsTest, ColorsPrint) {
4545
EXPECT_WRITE(stdout,
4646
fmt::print(bg(fmt::terminal_color::bright_magenta), "tbmagenta"),
4747
"\x1b[105mtbmagenta\x1b[0m");
48+
EXPECT_WRITE(stdout, fmt::print(fmt::emphasis::bold, "{}", std::string("a\0b", 3)),
49+
std::string("\x1b[1ma\0b\x1b[0m", 11));
4850
}
4951

5052
TEST(ColorsTest, Format) {

0 commit comments

Comments
 (0)