[Lldb-commits] [lldb] Colorize output when searching for symbols in lldb (PR #69422)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 14 01:34:18 PST 2023


================
@@ -403,9 +404,41 @@ bool Address::GetDescription(Stream &s, Target &target,
   return false;
 }
 
+void Address::DumpName(Stream *strm, llvm::StringRef text,
+                       const char *pattern) {
+  if (!pattern) {
+    strm->PutCString(text.data());
+    return;
+  }
+
+  llvm::Regex reg_pattern(pattern);
+  llvm::SmallVector<llvm::StringRef, 1> matches;
+  llvm::StringRef remaining = text;
+  std::string red_start =
+      lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}");
+  std::string reset_color =
+      lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.normal}");
----------------
DavidSpickett wrote:

I'm also wondering whether you could make this into a format string like:
```
lldb_private::ansi::FormatAnsiTerminalCodes("${ansi.fg.red}%s${ansi.normal}")
```
Then later use that with strm.printf like this: https://godbolt.org/z/zG6Tsn4WP

Assuming that stream's Printf does support `.*` like that.

Just saves you having to wrap the colour codes around the text each time and is a bit more obvious to the reader.

https://github.com/llvm/llvm-project/pull/69422


More information about the lldb-commits mailing list