2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/util/text-color.h"
19 #include "hphp/util/text-util.h"
25 ///////////////////////////////////////////////////////////////////////////////
27 const char *s_stdout_color
= nullptr;
28 const char *s_stderr_color
= nullptr;
30 const char *get_color_by_name(const std::string
&name
) {
31 auto upper
= toUpper(name
);
32 if (upper
== "BLACK" ) return ANSI_COLOR_BLACK
;
33 if (upper
== "RED" ) return ANSI_COLOR_RED
;
34 if (upper
== "GREEN" ) return ANSI_COLOR_GREEN
;
35 if (upper
== "BROWN" ) return ANSI_COLOR_BROWN
;
36 if (upper
== "BLUE" ) return ANSI_COLOR_BLUE
;
37 if (upper
== "MAGENTA" ) return ANSI_COLOR_MAGENTA
;
38 if (upper
== "CYAN" ) return ANSI_COLOR_CYAN
;
39 if (upper
== "GRAY" ) return ANSI_COLOR_GRAY
;
40 if (upper
== "DARK_GRAY" ) return ANSI_COLOR_DARK_GRAY
;
41 if (upper
== "LIGHT_RED" ) return ANSI_COLOR_LIGHT_RED
;
42 if (upper
== "LIGHT_GREEN" ) return ANSI_COLOR_LIGHT_GREEN
;
43 if (upper
== "YELLOW" ) return ANSI_COLOR_YELLOW
;
44 if (upper
== "LIGHT_BLUE" ) return ANSI_COLOR_LIGHT_BLUE
;
45 if (upper
== "LIGHT_MAGENTA" ) return ANSI_COLOR_LIGHT_MAGENTA
;
46 if (upper
== "LIGHT_CYAN" ) return ANSI_COLOR_LIGHT_CYAN
;
47 if (upper
== "WHITE" ) return ANSI_COLOR_WHITE
;
51 const char *get_bgcolor_by_name(const std::string
&name
) {
52 auto upper
= toUpper(name
);
53 if (upper
== "BLACK" ) return ANSI_BGCOLOR_BLACK
;
54 if (upper
== "RED" ) return ANSI_BGCOLOR_RED
;
55 if (upper
== "GREEN" ) return ANSI_BGCOLOR_GREEN
;
56 if (upper
== "BROWN" ) return ANSI_BGCOLOR_BROWN
;
57 if (upper
== "BLUE" ) return ANSI_BGCOLOR_BLUE
;
58 if (upper
== "MAGENTA" ) return ANSI_BGCOLOR_MAGENTA
;
59 if (upper
== "CYAN" ) return ANSI_BGCOLOR_CYAN
;
60 if (upper
== "GRAY" ) return ANSI_BGCOLOR_GRAY
;
64 void get_supported_colors(std::vector
<std::string
> &names
) {
65 names
.push_back("black" );
66 names
.push_back("red" );
67 names
.push_back("green" );
68 names
.push_back("brown" );
69 names
.push_back("blue" );
70 names
.push_back("magenta" );
71 names
.push_back("cyan" );
72 names
.push_back("gray" );
73 names
.push_back("dark_gray" );
74 names
.push_back("light_red" );
75 names
.push_back("light_green" );
76 names
.push_back("yellow" );
77 names
.push_back("light_blue" );
78 names
.push_back("light_magenta" );
79 names
.push_back("light_cyan" );
80 names
.push_back("white" );
83 std::string
add_bgcolor(const char *color
, const char *bgcolor
) {
84 assert(color
&& *color
&& color
[strlen(color
) - 1] == 'm');
85 assert(bgcolor
&& *bgcolor
);
87 std::string ret
= color
;
88 return ret
.substr(0, ret
.length() - 1) + bgcolor
;
91 ///////////////////////////////////////////////////////////////////////////////