[Lldb-commits] [lldb] 0acc9e4 - [lldb] Support "bright" ANSI colors

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 7 12:09:58 PST 2022


Author: Jonas Devlieghere
Date: 2022-03-07T12:09:53-08:00
New Revision: 0acc9e4b5edd8b39ff3d4c6d0e17f02007671c4e

URL: https://github.com/llvm/llvm-project/commit/0acc9e4b5edd8b39ff3d4c6d0e17f02007671c4e
DIFF: https://github.com/llvm/llvm-project/commit/0acc9e4b5edd8b39ff3d4c6d0e17f02007671c4e.diff

LOG: [lldb] Support "bright" ANSI colors

Support ANSI escape codes for bright colors variants. Most modern
terminals support them. LLDB is not using them in any of its defaults,
but they're useful for people who want to modify their preferred ANSI
prefix/suffix.

Differential revision: https://reviews.llvm.org/D121131

Added: 
    

Modified: 
    lldb/include/lldb/Utility/AnsiTerminal.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/AnsiTerminal.h b/lldb/include/lldb/Utility/AnsiTerminal.h
index c391adb2cf890..cc6765a605a2b 100644
--- a/lldb/include/lldb/Utility/AnsiTerminal.h
+++ b/lldb/include/lldb/Utility/AnsiTerminal.h
@@ -1,7 +1,3 @@
-#ifndef LLDB_UTILITY_ANSITERMINAL_H
-
-#define LLDB_UTILITY_ANSITERMINAL_H
-
 //===---------------------AnsiTerminal.h ------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -10,6 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#ifndef LLDB_UTILITY_ANSITERMINAL_H
+#define LLDB_UTILITY_ANSITERMINAL_H
+
 #define ANSI_FG_COLOR_BLACK 30
 #define ANSI_FG_COLOR_RED 31
 #define ANSI_FG_COLOR_GREEN 32
@@ -19,6 +18,15 @@
 #define ANSI_FG_COLOR_CYAN 36
 #define ANSI_FG_COLOR_WHITE 37
 
+#define ANSI_FG_COLOR_BRIGHT_BLACK 90
+#define ANSI_FG_COLOR_BRIGHT_RED 91
+#define ANSI_FG_COLOR_BRIGHT_GREEN 92
+#define ANSI_FG_COLOR_BRIGHT_YELLOW 93
+#define ANSI_FG_COLOR_BRIGHT_BLUE 94
+#define ANSI_FG_COLOR_BRIGHT_PURPLE 95
+#define ANSI_FG_COLOR_BRIGHT_CYAN 96
+#define ANSI_FG_COLOR_BRIGHT_WHITE 97
+
 #define ANSI_BG_COLOR_BLACK 40
 #define ANSI_BG_COLOR_RED 41
 #define ANSI_BG_COLOR_GREEN 42
@@ -28,6 +36,15 @@
 #define ANSI_BG_COLOR_CYAN 46
 #define ANSI_BG_COLOR_WHITE 47
 
+#define ANSI_BG_COLOR_BRIGHT_BLACK 100
+#define ANSI_BG_COLOR_BRIGHT_RED 101
+#define ANSI_BG_COLOR_BRIGHT_GREEN 102
+#define ANSI_BG_COLOR_BRIGHT_YELLOW 103
+#define ANSI_BG_COLOR_BRIGHT_BLUE 104
+#define ANSI_BG_COLOR_BRIGHT_PURPLE 105
+#define ANSI_BG_COLOR_BRIGHT_CYAN 106
+#define ANSI_BG_COLOR_BRIGHT_WHITE 107
+
 #define ANSI_SPECIAL_FRAMED 51
 #define ANSI_SPECIAL_ENCIRCLED 52
 
@@ -67,6 +84,7 @@ inline std::string FormatAnsiTerminalCodes(llvm::StringRef format,
                                            bool do_color = true) {
   // Convert "${ansi.XXX}" tokens to ansi values or clear them if do_color is
   // false.
+  // clang-format off
   static const struct {
     const char *name;
     const char *value;
@@ -81,6 +99,14 @@ inline std::string FormatAnsiTerminalCodes(llvm::StringRef format,
       {"fg.purple}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_PURPLE) ANSI_ESC_END},
       {"fg.cyan}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_CYAN) ANSI_ESC_END},
       {"fg.white}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_WHITE) ANSI_ESC_END},
+      {"fg.bright.black}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_BLACK) ANSI_ESC_END},
+      {"fg.bright.red}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_RED) ANSI_ESC_END},
+      {"fg.bright.green}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_GREEN) ANSI_ESC_END},
+      {"fg.bright.yellow}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_YELLOW) ANSI_ESC_END},
+      {"fg.bright.blue}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_BLUE) ANSI_ESC_END},
+      {"fg.bright.purple}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_PURPLE) ANSI_ESC_END},
+      {"fg.bright.cyan}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_CYAN) ANSI_ESC_END},
+      {"fg.bright.white}", ANSI_ESC_START _TO_STR(ANSI_FG_COLOR_BRIGHT_WHITE) ANSI_ESC_END},
       {"bg.black}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BLACK) ANSI_ESC_END},
       {"bg.red}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_RED) ANSI_ESC_END},
       {"bg.green}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_GREEN) ANSI_ESC_END},
@@ -89,6 +115,14 @@ inline std::string FormatAnsiTerminalCodes(llvm::StringRef format,
       {"bg.purple}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_PURPLE) ANSI_ESC_END},
       {"bg.cyan}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_CYAN) ANSI_ESC_END},
       {"bg.white}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_WHITE) ANSI_ESC_END},
+      {"bg.bright.black}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_BLACK) ANSI_ESC_END},
+      {"bg.bright.red}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_RED) ANSI_ESC_END},
+      {"bg.bright.green}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_GREEN) ANSI_ESC_END},
+      {"bg.bright.yellow}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_YELLOW) ANSI_ESC_END},
+      {"bg.bright.blue}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_BLUE) ANSI_ESC_END},
+      {"bg.bright.purple}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_PURPLE) ANSI_ESC_END},
+      {"bg.bright.cyan}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_CYAN) ANSI_ESC_END},
+      {"bg.bright.white}", ANSI_ESC_START _TO_STR(ANSI_BG_COLOR_BRIGHT_WHITE) ANSI_ESC_END},
       {"normal}", ANSI_ESC_START _TO_STR(ANSI_CTRL_NORMAL) ANSI_ESC_END},
       {"bold}", ANSI_ESC_START _TO_STR(ANSI_CTRL_BOLD) ANSI_ESC_END},
       {"faint}", ANSI_ESC_START _TO_STR(ANSI_CTRL_FAINT) ANSI_ESC_END},
@@ -106,6 +140,7 @@ inline std::string FormatAnsiTerminalCodes(llvm::StringRef format,
 #undef _TO_STR
 #undef _TO_STR2
   };
+  // clang-format on
   auto codes = llvm::makeArrayRef(g_color_tokens);
 
   static const char tok_hdr[] = "${ansi.";


        


More information about the lldb-commits mailing list