From 5e79a00178c22dc00d2e5cf73b7b639d44e3f73d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Sun, 3 Apr 2022 17:01:54 +0200 Subject: [PATCH] [lldb][gui] use symbolic names rather than hardcoded values --- lldb/source/Core/IOHandlerCursesGUI.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp index a30665c..2240954 100644 --- a/lldb/source/Core/IOHandlerCursesGUI.cpp +++ b/lldb/source/Core/IOHandlerCursesGUI.cpp @@ -28,6 +28,7 @@ #include "lldb/Core/StreamFile.h" #include "lldb/Core/ValueObjectUpdater.h" #include "lldb/Host/File.h" +#include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/Predicate.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/StreamString.h" @@ -495,7 +496,7 @@ public: if (use_blue_background) ::wattron(m_window, COLOR_PAIR(WhiteOnBlue)); while (!string.empty()) { - size_t esc_pos = string.find('\x1b'); + size_t esc_pos = string.find(ANSI_ESC_START); if (esc_pos == StringRef::npos) { string = string.substr(skip_first_count); if (!string.empty()) { @@ -517,26 +518,24 @@ public: string = string.drop_front(esc_pos); } } - bool consumed = string.consume_front("\x1b"); + bool consumed = string.consume_front(ANSI_ESC_START); assert(consumed); UNUSED_IF_ASSERT_DISABLED(consumed); // This is written to match our Highlighter classes, which seem to // generate only foreground color escape sequences. If necessary, this // will need to be extended. - if (!string.consume_front("[")) { - llvm::errs() << "Missing '[' in color escape sequence.\n"; - continue; - } // Only 8 basic foreground colors and reset, our Highlighter doesn't use // anything else. int value; if (!!string.consumeInteger(10, value) || // Returns false on success. - !(value == 0 || (value >= 30 && value <= 37))) { + !(value == 0 || + (value >= ANSI_FG_COLOR_BLACK && value <= ANSI_FG_COLOR_WHITE))) { llvm::errs() << "No valid color code in color escape sequence.\n"; continue; } - if (!string.consume_front("m")) { - llvm::errs() << "Missing 'm' in color escape sequence.\n"; + if (!string.consume_front(ANSI_ESC_END)) { + llvm::errs() << "Missing '" << ANSI_ESC_END + << "' in color escape sequence.\n"; continue; } if (value == 0) { // Reset. @@ -545,8 +544,8 @@ public: ::wattron(m_window, COLOR_PAIR(WhiteOnBlue)); } else { // Mapped directly to first 16 color pairs (black/blue background). - ::wattron(m_window, - COLOR_PAIR(value - 30 + 1 + (use_blue_background ? 8 : 0))); + ::wattron(m_window, COLOR_PAIR(value - ANSI_FG_COLOR_BLACK + 1 + + (use_blue_background ? 8 : 0))); } } wattr_set(m_window, saved_attr, saved_pair, nullptr); -- 2.7.4