Skip to content

Commit 7fd7ef3

Browse files
committed
Support color printing strings with zero bytes
This is a clean up after #1351.
1 parent 96f9142 commit 7fd7ef3

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
@@ -503,8 +503,7 @@ void vprint(std::FILE* f, const text_style& ts, const S& format,
503503
basic_format_args<buffer_context<Char> > args) {
504504
basic_memory_buffer<Char> buf;
505505
internal::vformat_to(buf, ts, to_string_view(format), args);
506-
buf.push_back(Char(0));
507-
internal::fputs(buf.data(), f);
506+
std::fwrite(buf.data(), 1, buf.size(), f);
508507
}
509508

510509
/**

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)