From 74107c9bd8c1df2b74d3cb4c0d98f0dcc60813d7 Mon Sep 17 00:00:00 2001 From: Remotion Date: Sat, 9 Jun 2018 15:13:02 +0200 Subject: [PATCH] Removed print_colored. Renamed enum colors back to color. --- include/fmt/colors.h | 28 ++++++++++++++++++++++------ include/fmt/core.h | 23 ----------------------- include/fmt/format-inl.h | 16 ---------------- test/colors_test.cc | 8 ++++---- test/format-test.cc | 7 ------- 5 files changed, 26 insertions(+), 56 deletions(-) diff --git a/include/fmt/colors.h b/include/fmt/colors.h index 36a3fbb3..becd11aa 100644 --- a/include/fmt/colors.h +++ b/include/fmt/colors.h @@ -16,7 +16,7 @@ FMT_BEGIN_NAMESPACE -enum class colors : uint32_t; +enum class color : uint32_t; // rgb is a struct for red, green and blue colors. // We use rgb as name because some editors will show it as color direct in the @@ -27,7 +27,7 @@ struct rgb { : r(r_), g(g_), b(b_) {} FMT_CONSTEXPR_DECL rgb(uint32_t hex) : r((hex >> 16) & 0xFF), g((hex >> 8) & 0xFF), b((hex) & 0xFF) {} - FMT_CONSTEXPR_DECL rgb(colors hex) + FMT_CONSTEXPR_DECL rgb(color hex) : r((uint32_t(hex) >> 16) & 0xFF), g((uint32_t(hex) >> 8) & 0xFF), b(uint32_t(hex) & 0xFF) {} uint8_t r; uint8_t g; @@ -74,24 +74,40 @@ inline void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) { std::fputs(RESET_COLOR, stdout); } +/** + Formats a string and prints it to stdout using ANSI escape sequences to + specify foreground color 'fd'. + Example: + fmt::print_rgb(fmt::color::red, "Elapsed time: {0:.2f} seconds", 1.23); + */ template inline void print_rgb(rgb fd, string_view format_str, const Args & ... args) { vprint_rgb(fd, format_str, make_format_args(args...)); } -// rgb foreground color +/** + Formats a string and prints it to stdout using ANSI escape sequences to + specify foreground color 'fd'. + Example: + fmt::print(fmt::color::red, "Elapsed time: {0:.2f} seconds", 1.23); + */ template inline void print(rgb fd, string_view format_str, const Args & ... args) { vprint_rgb(fd, format_str, make_format_args(args...)); } -// rgb foreground color and background color +/** + Formats a string and prints it to stdout using ANSI escape sequences to + specify foreground color 'fd' and background color 'bg'. + Example: + fmt::print(fmt::color::red, fmt::color::black, "Elapsed time: {0:.2f} seconds", 1.23); + */ template inline void print(rgb fd, rgb bg, string_view format_str, const Args & ... args) { vprint_rgb(fd, bg, format_str, make_format_args(args...)); } -enum class colors : uint32_t { +enum class color : uint32_t { alice_blue = 0xF0F8FF, // rgb(240,248,255) antique_white = 0xFAEBD7, // rgb(250,235,215) aqua = 0x00FFFF, // rgb(0,255,255) @@ -233,7 +249,7 @@ enum class colors : uint32_t { white_smoke = 0xF5F5F5, // rgb(245,245,245) yellow = 0xFFFF00, // rgb(255,255,0) yellow_green = 0x9ACD32, // rgb(154,205,50) -}; // enum class colors +}; // enum class color FMT_END_NAMESPACE diff --git a/include/fmt/core.h b/include/fmt/core.h index cf87bce8..7568007b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1181,29 +1181,6 @@ inline internal::named_arg arg(wstring_view name, const T &arg) { template void arg(S, internal::named_arg) FMT_DELETED; -enum color { black, red, green, yellow, blue, magenta, cyan, white }; - -FMT_API void vprint_colored(color c, string_view format, format_args args); -FMT_API void vprint_colored(color c, wstring_view format, wformat_args args); - -/** - Formats a string and prints it to stdout using ANSI escape sequences to - specify color (experimental). - Example: - fmt::print_colored(fmt::RED, "Elapsed time: {0:.2f} seconds", 1.23); - */ -template -inline void print_colored(color c, string_view format_str, - const Args & ... args) { - vprint_colored(c, format_str, make_format_args(args...)); -} - -template -inline void print_colored(color c, wstring_view format_str, - const Args & ... args) { - vprint_colored(c, format_str, make_format_args(args...)); -} - format_context::iterator vformat_to( internal::buffer &buf, string_view format_str, format_args args); wformat_context::iterator vformat_to( diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index ac61d93a..c5578894 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -499,22 +499,6 @@ FMT_FUNC void vprint(wstring_view format_str, wformat_args args) { vprint(stdout, format_str, args); } -FMT_FUNC void vprint_colored(color c, string_view format, format_args args) { - char escape[] = "\x1b[30m"; - escape[3] = static_cast('0' + c); - std::fputs(escape, stdout); - vprint(format, args); - std::fputs(RESET_COLOR, stdout); -} - -FMT_FUNC void vprint_colored(color c, wstring_view format, wformat_args args) { - wchar_t escape[] = L"\x1b[30m"; - escape[3] = static_cast('0' + c); - std::fputws(escape, stdout); - vprint(format, args); - std::fputws(WRESET_COLOR, stdout); -} - FMT_FUNC locale locale_provider::locale() { return fmt::locale(); } FMT_END_NAMESPACE diff --git a/test/colors_test.cc b/test/colors_test.cc index b8da20d9..b2f9c08d 100644 --- a/test/colors_test.cc +++ b/test/colors_test.cc @@ -30,9 +30,9 @@ TEST(ColorsTest, RgbTest) { } TEST(ColorsTest, Colors) { - fmt::print(fmt::colors::blue,"blue \n"); // \x1b[38;2;000;000;255mblue \n\x1b[0m - fmt::print(fmt::colors::medium_spring_green,"medium_spring_green \n"); // \x1b[38;2;000;250;154mmedium_spring_green \n\x1b[0m - fmt::print(fmt::colors::light_golden_rod_yellow,"light_golden_rod_yellow \n"); // \x1b[38;2;250;250;210mlight_golden_rod_yellow \n\x1b[0m + fmt::print(fmt::color::blue,"blue \n"); // \x1b[38;2;000;000;255mblue \n\x1b[0m + fmt::print(fmt::color::medium_spring_green,"medium_spring_green \n"); // \x1b[38;2;000;250;154mmedium_spring_green \n\x1b[0m + fmt::print(fmt::color::light_golden_rod_yellow,"light_golden_rod_yellow \n"); // \x1b[38;2;250;250;210mlight_golden_rod_yellow \n\x1b[0m - EXPECT_WRITE(stdout, fmt::print(fmt::colors::blue,"blue"), "\x1b[38;2;000;000;255mblue\x1b[0m"); + EXPECT_WRITE(stdout, fmt::print(fmt::color::blue,"blue"), "\x1b[38;2;000;000;255mblue\x1b[0m"); } diff --git a/test/format-test.cc b/test/format-test.cc index e0cddd14..e0f3febb 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1266,13 +1266,6 @@ TEST(FormatTest, Print) { #endif } -#if FMT_USE_FILE_DESCRIPTORS -TEST(FormatTest, PrintColored) { - EXPECT_WRITE(stdout, fmt::print_colored(fmt::red, "Hello, {}!\n", "world"), - "\x1b[31mHello, world!\n\x1b[0m"); -} -#endif - TEST(FormatTest, Variadic) { EXPECT_EQ("abc1", format("{}c{}", "ab", 1)); EXPECT_EQ(L"abc1", format(L"{}c{}", L"ab", 1));