Skip to content

Commit 5e79a00

Browse files
committed
[lldb][gui] use symbolic names rather than hardcoded values
1 parent 5c540c7 commit 5e79a00

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lldb/source/Core/IOHandlerCursesGUI.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "lldb/Core/StreamFile.h"
2929
#include "lldb/Core/ValueObjectUpdater.h"
3030
#include "lldb/Host/File.h"
31+
#include "lldb/Utility/AnsiTerminal.h"
3132
#include "lldb/Utility/Predicate.h"
3233
#include "lldb/Utility/Status.h"
3334
#include "lldb/Utility/StreamString.h"
@@ -495,7 +496,7 @@ class Surface {
495496
if (use_blue_background)
496497
::wattron(m_window, COLOR_PAIR(WhiteOnBlue));
497498
while (!string.empty()) {
498-
size_t esc_pos = string.find('\x1b');
499+
size_t esc_pos = string.find(ANSI_ESC_START);
499500
if (esc_pos == StringRef::npos) {
500501
string = string.substr(skip_first_count);
501502
if (!string.empty()) {
@@ -517,26 +518,24 @@ class Surface {
517518
string = string.drop_front(esc_pos);
518519
}
519520
}
520-
bool consumed = string.consume_front("\x1b");
521+
bool consumed = string.consume_front(ANSI_ESC_START);
521522
assert(consumed);
522523
UNUSED_IF_ASSERT_DISABLED(consumed);
523524
// This is written to match our Highlighter classes, which seem to
524525
// generate only foreground color escape sequences. If necessary, this
525526
// will need to be extended.
526-
if (!string.consume_front("[")) {
527-
llvm::errs() << "Missing '[' in color escape sequence.\n";
528-
continue;
529-
}
530527
// Only 8 basic foreground colors and reset, our Highlighter doesn't use
531528
// anything else.
532529
int value;
533530
if (!!string.consumeInteger(10, value) || // Returns false on success.
534-
!(value == 0 || (value >= 30 && value <= 37))) {
531+
!(value == 0 ||
532+
(value >= ANSI_FG_COLOR_BLACK && value <= ANSI_FG_COLOR_WHITE))) {
535533
llvm::errs() << "No valid color code in color escape sequence.\n";
536534
continue;
537535
}
538-
if (!string.consume_front("m")) {
539-
llvm::errs() << "Missing 'm' in color escape sequence.\n";
536+
if (!string.consume_front(ANSI_ESC_END)) {
537+
llvm::errs() << "Missing '" << ANSI_ESC_END
538+
<< "' in color escape sequence.\n";
540539
continue;
541540
}
542541
if (value == 0) { // Reset.
@@ -545,8 +544,8 @@ class Surface {
545544
::wattron(m_window, COLOR_PAIR(WhiteOnBlue));
546545
} else {
547546
// Mapped directly to first 16 color pairs (black/blue background).
548-
::wattron(m_window,
549-
COLOR_PAIR(value - 30 + 1 + (use_blue_background ? 8 : 0)));
547+
::wattron(m_window, COLOR_PAIR(value - ANSI_FG_COLOR_BLACK + 1 +
548+
(use_blue_background ? 8 : 0)));
550549
}
551550
}
552551
wattr_set(m_window, saved_attr, saved_pair, nullptr);

0 commit comments

Comments
 (0)