From c8b8597e39ff3d79a80cff10867d651dc5641272 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Sat, 6 Jul 2024 21:31:40 -0400 Subject: [PATCH] fixed issue with color in console_output::get_code --- src/console_output.cc | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/console_output.cc b/src/console_output.cc index 43cb24a..4dae457 100644 --- a/src/console_output.cc +++ b/src/console_output.cc @@ -41,29 +41,20 @@ std::string console_output::get_code(const int attr) { if (attr & A_UNDERLINE) result += "4;"; - if (attr & COLOR_PAIR(COLOR_BLACK)) - result += "30;"; - - if (attr & COLOR_PAIR(COLOR_RED)) - result += "31;"; - - if (attr & COLOR_PAIR(COLOR_GREEN)) - result += "32;"; - - if (attr & COLOR_PAIR(COLOR_YELLOW)) - result += "33;"; - - if (attr & COLOR_PAIR(COLOR_BLUE)) - result += "34;"; - - if (attr & COLOR_PAIR(COLOR_MAGENTA)) - result += "35;"; - - if (attr & COLOR_PAIR(COLOR_CYAN)) - result += "36;"; - - if (attr & COLOR_PAIR(COLOR_WHITE)) + if ((attr & COLOR_PAIR(COLOR_WHITE)) == COLOR_PAIR(COLOR_WHITE)) result += "37;"; + else if ((attr & COLOR_PAIR(COLOR_CYAN)) == COLOR_PAIR(COLOR_CYAN)) + result += "36;"; + else if ((attr & COLOR_PAIR(COLOR_MAGENTA)) == COLOR_PAIR(COLOR_MAGENTA)) + result += "35;"; + else if ((attr & COLOR_PAIR(COLOR_BLUE)) == COLOR_PAIR(COLOR_BLUE)) + result += "34;"; + else if ((attr & COLOR_PAIR(COLOR_YELLOW)) == COLOR_PAIR(COLOR_YELLOW)) + result += "33;"; + else if ((attr & COLOR_PAIR(COLOR_RED)) == COLOR_PAIR(COLOR_RED)) + result += "31;"; + else if ((attr & COLOR_PAIR(COLOR_GREEN)) == COLOR_PAIR(COLOR_GREEN)) + result += "32;"; result[result.length() - 1] = 'm'; return result;