@@ -273,6 +273,32 @@ struct KeyHelp {
273273 const char *description;
274274};
275275
276+ // COLOR_PAIR index names
277+ enum {
278+ // First 16 colors are 8 black background and 8 blue background colors,
279+ // needed by OutputColoredStringTruncated().
280+ BlackOnBlack = 1 ,
281+ RedOnBlack,
282+ GreenOnBlack,
283+ YellowOnBlack,
284+ BlueOnBlack,
285+ MagentaOnBlack,
286+ CyanOnBlack,
287+ WhiteOnBlack,
288+ BlackOnBlue,
289+ RedOnBlue,
290+ GreenOnBlue,
291+ YellowOnBlue,
292+ BlueOnBlue,
293+ MagentaOnBlue,
294+ CyanOnBlue,
295+ WhiteOnBlue,
296+ // Other colors, as needed.
297+ BlackOnWhite,
298+ MagentaOnWhite,
299+ LastColorPairIndex = MagentaOnWhite
300+ };
301+
276302class WindowDelegate {
277303public:
278304 virtual ~WindowDelegate () = default ;
@@ -462,7 +488,7 @@ class Window {
462488 int saved_opts;
463489 ::wattr_get (m_window, &saved_attr, &saved_pair, &saved_opts);
464490 if (use_blue_background)
465- ::wattron (m_window, COLOR_PAIR(16 ));
491+ ::wattron (m_window, COLOR_PAIR(WhiteOnBlue ));
466492 while (!string.empty ()) {
467493 size_t esc_pos = string.find (' \x1b ' );
468494 if (esc_pos == StringRef::npos) {
@@ -498,7 +524,7 @@ class Window {
498524 if (value == 0 ) { // Reset.
499525 ::wattr_set (m_window, saved_attr, saved_pair, &saved_opts);
500526 if (use_blue_background)
501- ::wattron (m_window, COLOR_PAIR(16 ));
527+ ::wattron (m_window, COLOR_PAIR(WhiteOnBlue ));
502528 } else {
503529 // Mapped directly to first 16 color pairs (black/blue background).
504530 ::wattron (m_window,
@@ -596,7 +622,7 @@ class Window {
596622 void DrawTitleBox (const char *title, const char *bottom_message = nullptr ) {
597623 attr_t attr = 0 ;
598624 if (IsActive ())
599- attr = A_BOLD | COLOR_PAIR (18 );
625+ attr = A_BOLD | COLOR_PAIR (BlackOnWhite );
600626 else
601627 attr = 0 ;
602628 if (attr)
@@ -1026,14 +1052,14 @@ void Menu::DrawMenuTitle(Window &window, bool highlight) {
10261052
10271053 if (m_key_name.empty ()) {
10281054 if (!underlined_shortcut && llvm::isPrint (m_key_value)) {
1029- window.AttributeOn (COLOR_PAIR (19 ));
1055+ window.AttributeOn (COLOR_PAIR (MagentaOnWhite ));
10301056 window.Printf (" (%c)" , m_key_value);
1031- window.AttributeOff (COLOR_PAIR (19 ));
1057+ window.AttributeOff (COLOR_PAIR (MagentaOnWhite ));
10321058 }
10331059 } else {
1034- window.AttributeOn (COLOR_PAIR (19 ));
1060+ window.AttributeOn (COLOR_PAIR (MagentaOnWhite ));
10351061 window.Printf (" (%s)" , m_key_name.c_str ());
1036- window.AttributeOff (COLOR_PAIR (19 ));
1062+ window.AttributeOff (COLOR_PAIR (MagentaOnWhite ));
10371063 }
10381064 }
10391065}
@@ -1045,7 +1071,7 @@ bool Menu::WindowDelegateDraw(Window &window, bool force) {
10451071 Menu::Type menu_type = GetType ();
10461072 switch (menu_type) {
10471073 case Menu::Type::Bar: {
1048- window.SetBackground (18 );
1074+ window.SetBackground (BlackOnWhite );
10491075 window.MoveCursor (0 , 0 );
10501076 for (size_t i = 0 ; i < num_submenus; ++i) {
10511077 Menu *menu = submenus[i].get ();
@@ -1065,7 +1091,7 @@ bool Menu::WindowDelegateDraw(Window &window, bool force) {
10651091 int cursor_x = 0 ;
10661092 int cursor_y = 0 ;
10671093 window.Erase ();
1068- window.SetBackground (18 );
1094+ window.SetBackground (BlackOnWhite );
10691095 window.Box ();
10701096 for (size_t i = 0 ; i < num_submenus; ++i) {
10711097 const bool is_selected = (i == static_cast <size_t >(selected_idx));
@@ -2440,7 +2466,7 @@ class ValueObjectListDelegate : public WindowDelegate {
24402466
24412467 attr_t changd_attr = 0 ;
24422468 if (valobj->GetValueDidChange ())
2443- changd_attr = COLOR_PAIR (2 ) | A_BOLD;
2469+ changd_attr = COLOR_PAIR (RedOnBlack ) | A_BOLD;
24442470
24452471 if (value && value[0 ]) {
24462472 window.PutCStringTruncated (1 , " = " );
@@ -3309,7 +3335,7 @@ class StatusBarWindowDelegate : public WindowDelegate {
33093335 Thread *thread = exe_ctx.GetThreadPtr ();
33103336 StackFrame *frame = exe_ctx.GetFramePtr ();
33113337 window.Erase ();
3312- window.SetBackground (18 );
3338+ window.SetBackground (BlackOnWhite );
33133339 window.MoveCursor (0 , 0 );
33143340 if (process) {
33153341 const StateType state = process->GetState ();
@@ -3581,7 +3607,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
35813607 }
35823608
35833609 const attr_t selected_highlight_attr = A_REVERSE;
3584- const attr_t pc_highlight_attr = COLOR_PAIR (9 );
3610+ const attr_t pc_highlight_attr = COLOR_PAIR (BlackOnBlue );
35853611
35863612 for (size_t i = 0 ; i < num_visible_lines; ++i) {
35873613 const uint32_t curr_line = m_first_visible_line + i;
@@ -3600,7 +3626,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
36003626 highlight_attr = selected_highlight_attr;
36013627
36023628 if (bp_lines.find (curr_line + 1 ) != bp_lines.end ())
3603- bp_attr = COLOR_PAIR (18 );
3629+ bp_attr = COLOR_PAIR (BlackOnWhite );
36043630
36053631 if (bp_attr)
36063632 window.AttributeOn (bp_attr);
@@ -3641,7 +3667,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
36413667 window.Printf (" %*s" , desc_x - window.GetCursorX (), " " );
36423668 window.MoveCursor (window_width - stop_description_len - 16 ,
36433669 line_y);
3644- const attr_t stop_reason_attr = COLOR_PAIR (17 );
3670+ const attr_t stop_reason_attr = COLOR_PAIR (WhiteOnBlue );
36453671 window.AttributeOn (stop_reason_attr);
36463672 window.PrintfTruncated (1 , " <<< Thread %u: %s " ,
36473673 thread->GetIndexID (), stop_description);
@@ -3685,7 +3711,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
36853711 }
36863712
36873713 const attr_t selected_highlight_attr = A_REVERSE;
3688- const attr_t pc_highlight_attr = COLOR_PAIR (17 );
3714+ const attr_t pc_highlight_attr = COLOR_PAIR (WhiteOnBlue );
36893715
36903716 StreamString strm;
36913717
@@ -3733,7 +3759,7 @@ class SourceFileWindowDelegate : public WindowDelegate {
37333759
37343760 if (bp_file_addrs.find (inst->GetAddress ().GetFileAddress ()) !=
37353761 bp_file_addrs.end ())
3736- bp_attr = COLOR_PAIR (18 );
3762+ bp_attr = COLOR_PAIR (BlackOnWhite );
37373763
37383764 if (bp_attr)
37393765 window.AttributeOn (bp_attr);
@@ -4270,10 +4296,10 @@ void IOHandlerCursesGUI::Activate() {
42704296 init_pair (14 , COLOR_MAGENTA, COLOR_BLUE);
42714297 init_pair (15 , COLOR_CYAN, COLOR_BLUE);
42724298 init_pair (16 , COLOR_WHITE, COLOR_BLUE);
4273-
4274- init_pair (17 , COLOR_WHITE, COLOR_BLUE );
4275- init_pair (18 , COLOR_BLACK , COLOR_WHITE);
4276- init_pair ( 19 , COLOR_MAGENTA, COLOR_WHITE );
4299+ // These must match the order in the color indexes enum.
4300+ init_pair (17 , COLOR_BLACK, COLOR_WHITE );
4301+ init_pair (18 , COLOR_MAGENTA , COLOR_WHITE);
4302+ static_assert (LastColorPairIndex == 18 , " Color indexes do not match. " );
42774303 }
42784304}
42794305
0 commit comments