From d8434baa03b4ab0e1a4b5c4f99d6390155840ced Mon Sep 17 00:00:00 2001 From: Michael Winterberg Date: Wed, 6 Mar 2019 09:23:34 -0800 Subject: [PATCH] Declare the size of RESET_COLOR. This is so that the format with a text_tyle will compile even if header-only mode isn't enabled. Addresses #1063. --- include/fmt/format.h | 4 ++-- test/format-test.cc | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index f40c671e..6923df55 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -766,8 +766,8 @@ template struct FMT_API basic_data { static const char DIGITS[]; static const char FOREGROUND_COLOR[]; static const char BACKGROUND_COLOR[]; - static const char RESET_COLOR[]; - static const wchar_t WRESET_COLOR[]; + static const char RESET_COLOR[5]; + static const wchar_t WRESET_COLOR[5]; }; #if FMT_USE_EXTERN_TEMPLATES diff --git a/test/format-test.cc b/test/format-test.cc index 51ce763b..5dab5223 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -21,6 +21,7 @@ #endif #include "fmt/format.h" +#include "fmt/color.h" #include "gmock.h" #include "gtest-extra.h" #include "mock-allocator.h" @@ -2492,3 +2493,9 @@ TEST(FormatTest, U8StringViewLiteral) { TEST(FormatTest, FormatU8String) { EXPECT_EQ(format(fmt::u8string_view("{}"), 42), fmt::u8string_view("42")); } + +TEST(FormatTest, EmphasisNonHeaderOnly) { + // ensure this compiles even if FMT_HEADER_ONLY is not defined. + EXPECT_EQ(fmt::format(fmt::emphasis::bold, "bold error"), + "\x1b[1mbold error\x1b[0m"); +}