9#ifndef LLDB_UTILITY_ANSITERMINAL_H
10#define LLDB_UTILITY_ANSITERMINAL_H
12#define ANSI_FG_COLOR_BLACK 30
13#define ANSI_FG_COLOR_RED 31
14#define ANSI_FG_COLOR_GREEN 32
15#define ANSI_FG_COLOR_YELLOW 33
16#define ANSI_FG_COLOR_BLUE 34
17#define ANSI_FG_COLOR_PURPLE 35
18#define ANSI_FG_COLOR_CYAN 36
19#define ANSI_FG_COLOR_WHITE 37
21#define ANSI_FG_COLOR_BRIGHT_BLACK 90
22#define ANSI_FG_COLOR_BRIGHT_RED 91
23#define ANSI_FG_COLOR_BRIGHT_GREEN 92
24#define ANSI_FG_COLOR_BRIGHT_YELLOW 93
25#define ANSI_FG_COLOR_BRIGHT_BLUE 94
26#define ANSI_FG_COLOR_BRIGHT_PURPLE 95
27#define ANSI_FG_COLOR_BRIGHT_CYAN 96
28#define ANSI_FG_COLOR_BRIGHT_WHITE 97
30#define ANSI_BG_COLOR_BLACK 40
31#define ANSI_BG_COLOR_RED 41
32#define ANSI_BG_COLOR_GREEN 42
33#define ANSI_BG_COLOR_YELLOW 43
34#define ANSI_BG_COLOR_BLUE 44
35#define ANSI_BG_COLOR_PURPLE 45
36#define ANSI_BG_COLOR_CYAN 46
37#define ANSI_BG_COLOR_WHITE 47
39#define ANSI_BG_COLOR_BRIGHT_BLACK 100
40#define ANSI_BG_COLOR_BRIGHT_RED 101
41#define ANSI_BG_COLOR_BRIGHT_GREEN 102
42#define ANSI_BG_COLOR_BRIGHT_YELLOW 103
43#define ANSI_BG_COLOR_BRIGHT_BLUE 104
44#define ANSI_BG_COLOR_BRIGHT_PURPLE 105
45#define ANSI_BG_COLOR_BRIGHT_CYAN 106
46#define ANSI_BG_COLOR_BRIGHT_WHITE 107
48#define ANSI_SPECIAL_FRAMED 51
49#define ANSI_SPECIAL_ENCIRCLED 52
51#define ANSI_CTRL_NORMAL 0
52#define ANSI_CTRL_BOLD 1
53#define ANSI_CTRL_FAINT 2
54#define ANSI_CTRL_ITALIC 3
55#define ANSI_CTRL_UNDERLINE 4
56#define ANSI_CTRL_SLOW_BLINK 5
57#define ANSI_CTRL_FAST_BLINK 6
58#define ANSI_CTRL_IMAGE_NEGATIVE 7
59#define ANSI_CTRL_CONCEAL 8
60#define ANSI_CTRL_CROSSED_OUT 9
62#define ANSI_ESC_START "\033["
63#define ANSI_ESC_END "m"
66#define ANSI_DEF_STR(s) ANSI_STR(s)
68#define ANSI_ESCAPE1(s) ANSI_ESC_START ANSI_DEF_STR(s) ANSI_ESC_END
70#define ANSI_1_CTRL(ctrl1) "\033["##ctrl1 ANSI_ESC_END
71#define ANSI_2_CTRL(ctrl1, ctrl2) "\033["##ctrl1 ";"##ctrl2 ANSI_ESC_END
73#include "llvm/ADT/ArrayRef.h"
74#include "llvm/ADT/STLExtras.h"
75#include "llvm/ADT/StringRef.h"
84 bool do_color =
true) {
91 } g_color_tokens[] = {
92#define _TO_STR2(_val) #_val
93#define _TO_STR(_val) _TO_STR2(_val)
140 auto codes = llvm::ArrayRef(g_color_tokens);
142 static const char tok_hdr[] =
"${ansi.";
145 while (!format.empty()) {
146 llvm::StringRef left, right;
147 std::tie(left, right) = format.split(tok_hdr);
151 if (left == format && right.empty()) {
156 bool found_code =
false;
157 for (
const auto &code : codes) {
158 if (!right.consume_front(code.name))
162 fmt.append(code.value);
#define ANSI_FG_COLOR_BRIGHT_GREEN
#define ANSI_BG_COLOR_BRIGHT_BLUE
#define ANSI_BG_COLOR_PURPLE
#define ANSI_CTRL_UNDERLINE
#define ANSI_BG_COLOR_BRIGHT_WHITE
#define ANSI_BG_COLOR_BRIGHT_RED
#define ANSI_BG_COLOR_RED
#define ANSI_FG_COLOR_BLACK
#define ANSI_FG_COLOR_BRIGHT_CYAN
#define ANSI_FG_COLOR_BRIGHT_BLACK
#define ANSI_BG_COLOR_YELLOW
#define ANSI_FG_COLOR_BRIGHT_WHITE
#define ANSI_BG_COLOR_BLACK
#define ANSI_FG_COLOR_BRIGHT_YELLOW
#define ANSI_FG_COLOR_YELLOW
#define ANSI_FG_COLOR_PURPLE
#define ANSI_BG_COLOR_CYAN
#define ANSI_FG_COLOR_BRIGHT_RED
#define ANSI_BG_COLOR_BRIGHT_YELLOW
#define ANSI_BG_COLOR_GREEN
#define ANSI_CTRL_SLOW_BLINK
#define ANSI_FG_COLOR_RED
#define ANSI_BG_COLOR_BLUE
#define ANSI_FG_COLOR_BRIGHT_BLUE
#define ANSI_FG_COLOR_CYAN
#define ANSI_CTRL_FAST_BLINK
#define ANSI_CTRL_CROSSED_OUT
#define ANSI_CTRL_IMAGE_NEGATIVE
#define ANSI_BG_COLOR_WHITE
#define ANSI_CTRL_CONCEAL
#define ANSI_FG_COLOR_GREEN
#define ANSI_FG_COLOR_BLUE
#define ANSI_BG_COLOR_BRIGHT_GREEN
#define ANSI_FG_COLOR_BRIGHT_PURPLE
#define ANSI_BG_COLOR_BRIGHT_CYAN
#define ANSI_FG_COLOR_WHITE
#define ANSI_BG_COLOR_BRIGHT_PURPLE
#define ANSI_BG_COLOR_BRIGHT_BLACK
std::string FormatAnsiTerminalCodes(llvm::StringRef format, bool do_color=true)
A class that represents a running process on the host machine.