From b273b3597ff377b33079ef155bfc1456af138b9b Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 9 Nov 2021 07:51:54 +0100 Subject: [PATCH] Rang: enable also other 3-/4-bit ANSI colors Enabled remaining 3-/4-bit ANSI colors as per: https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit rang.hpp header is now synced with: https://github.com/MartinPulec/rang/blob/master/include/rang.hpp --- src/rang.hpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/rang.hpp b/src/rang.hpp index de5646fad..0a79b776f 100644 --- a/src/rang.hpp +++ b/src/rang.hpp @@ -1,7 +1,3 @@ -/* - * Header is obtained from here: - * https://github.com/agauniyal/rang - */ #ifndef RANG_DOT_HPP #define RANG_DOT_HPP @@ -74,7 +70,15 @@ enum class fg { magenta = 35, cyan = 36, gray = 37, - reset = 39 + reset = 39, + bright_black = 90, + bright_red, + bright_green, + bright_yellow, + bright_blue, + bright_magenta, + bright_cyan, + bright_white, }; enum class bg { @@ -86,7 +90,15 @@ enum class bg { magenta = 45, cyan = 46, gray = 47, - reset = 49 + reset = 49, + bright_black = 100, + bright_red, + bright_green, + bright_yellow, + bright_blue, + bright_magenta, + bright_cyan, + bright_white, }; enum class fgB { @@ -356,7 +368,8 @@ namespace rang_implementation { inline void setWinSGR(rang::bg col, SGR &state) noexcept { if (col != rang::bg::reset) { - state.bgColor = ansi2attr(static_cast(col) - 40); + auto val = static_cast(col); + state.bgColor = ansi2attr(val - (val < static_cast(rang::fg::reset) ? 40 : 100)); } else { state.bgColor = defaultState().bgColor; } @@ -365,7 +378,8 @@ namespace rang_implementation { inline void setWinSGR(rang::fg col, SGR &state) noexcept { if (col != rang::fg::reset) { - state.fgColor = ansi2attr(static_cast(col) - 30); + auto val = static_cast(col); + state.fgColor = ansi2attr(val - (val < static_cast(rang::fg::reset) ? 30 : 90)); } else { state.fgColor = defaultState().fgColor; }