From 8c6215f5de5eb680e1dd697362fb2104d0b116bc Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 8 Nov 2020 07:24:07 -0800 Subject: [PATCH] Fix fmt/color.h --- include/fmt/color.h | 69 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index 0ceb4429..ee85306b 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -261,32 +261,12 @@ class text_style { } FMT_DEPRECATED FMT_CONSTEXPR text_style& operator&=(const text_style& rhs) { - if (!set_foreground_color) { - set_foreground_color = rhs.set_foreground_color; - foreground_color = rhs.foreground_color; - } else if (rhs.set_foreground_color) { - if (!foreground_color.is_rgb || !rhs.foreground_color.is_rgb) - FMT_THROW(format_error("can't AND a terminal color")); - foreground_color.value.rgb_color &= rhs.foreground_color.value.rgb_color; - } - - if (!set_background_color) { - set_background_color = rhs.set_background_color; - background_color = rhs.background_color; - } else if (rhs.set_background_color) { - if (!background_color.is_rgb || !rhs.background_color.is_rgb) - FMT_THROW(format_error("can't AND a terminal color")); - background_color.value.rgb_color &= rhs.background_color.value.rgb_color; - } - - ems = static_cast(static_cast(ems) & - static_cast(rhs.ems)); - return *this; + return and_assign(rhs); } FMT_DEPRECATED friend FMT_CONSTEXPR text_style operator&(text_style lhs, const text_style& rhs) { - return lhs &= rhs; + return lhs.and_assign(rhs); } FMT_CONSTEXPR bool has_foreground() const FMT_NOEXCEPT { @@ -326,17 +306,36 @@ class text_style { } } - /** Creates a text style from the foreground (text) color. */ - friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground) - FMT_NOEXCEPT { - return text_style(true, foreground); + // DEPRECATED! + FMT_CONSTEXPR text_style& and_assign(const text_style& rhs) { + if (!set_foreground_color) { + set_foreground_color = rhs.set_foreground_color; + foreground_color = rhs.foreground_color; + } else if (rhs.set_foreground_color) { + if (!foreground_color.is_rgb || !rhs.foreground_color.is_rgb) + FMT_THROW(format_error("can't AND a terminal color")); + foreground_color.value.rgb_color &= rhs.foreground_color.value.rgb_color; + } + + if (!set_background_color) { + set_background_color = rhs.set_background_color; + background_color = rhs.background_color; + } else if (rhs.set_background_color) { + if (!background_color.is_rgb || !rhs.background_color.is_rgb) + FMT_THROW(format_error("can't AND a terminal color")); + background_color.value.rgb_color &= rhs.background_color.value.rgb_color; + } + + ems = static_cast(static_cast(ems) & + static_cast(rhs.ems)); + return *this; } - /** Creates a text style from the background color. */ + friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground) + FMT_NOEXCEPT; + friend FMT_CONSTEXPR_DECL text_style bg(detail::color_type background) - FMT_NOEXCEPT { - return text_style(false, background); - } + FMT_NOEXCEPT; detail::color_type foreground_color; detail::color_type background_color; @@ -345,6 +344,16 @@ class text_style { emphasis ems; }; +/** Creates a text style from the foreground (text) color. */ +FMT_CONSTEXPR text_style fg(detail::color_type foreground) FMT_NOEXCEPT { + return text_style(true, foreground); +} + +/** Creates a text style from the background color. */ +FMT_CONSTEXPR text_style bg(detail::color_type background) FMT_NOEXCEPT { + return text_style(false, background); +} + FMT_CONSTEXPR text_style operator|(emphasis lhs, emphasis rhs) FMT_NOEXCEPT { return text_style(lhs) | rhs; }