make (array) of ArrayObject return the contents
[hiphop-php.git] / hphp / util / text-color.cpp
blob70c37cfb4777e523411e3a4bcd35c4bda2bd9bab
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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"
18 #include "util.h"
20 namespace HPHP {
21 ///////////////////////////////////////////////////////////////////////////////
23 const char *s_stdout_color = nullptr;
24 const char *s_stderr_color = nullptr;
26 const char *get_color_by_name(const char *name) {
27 string upper = Util::toUpper(name);
28 if (upper == "BLACK" ) return ANSI_COLOR_BLACK;
29 if (upper == "RED" ) return ANSI_COLOR_RED;
30 if (upper == "GREEN" ) return ANSI_COLOR_GREEN;
31 if (upper == "BROWN" ) return ANSI_COLOR_BROWN;
32 if (upper == "BLUE" ) return ANSI_COLOR_BLUE;
33 if (upper == "MAGENTA" ) return ANSI_COLOR_MAGENTA;
34 if (upper == "CYAN" ) return ANSI_COLOR_CYAN;
35 if (upper == "GRAY" ) return ANSI_COLOR_GRAY;
36 if (upper == "DARK_GRAY" ) return ANSI_COLOR_DARK_GRAY;
37 if (upper == "LIGHT_RED" ) return ANSI_COLOR_LIGHT_RED;
38 if (upper == "LIGHT_GREEN" ) return ANSI_COLOR_LIGHT_GREEN;
39 if (upper == "YELLOW" ) return ANSI_COLOR_YELLOW;
40 if (upper == "LIGHT_BLUE" ) return ANSI_COLOR_LIGHT_BLUE;
41 if (upper == "LIGHT_MAGENTA" ) return ANSI_COLOR_LIGHT_MAGENTA;
42 if (upper == "LIGHT_CYAN" ) return ANSI_COLOR_LIGHT_CYAN;
43 if (upper == "WHITE" ) return ANSI_COLOR_WHITE;
44 return nullptr;
47 const char *get_bgcolor_by_name(const char *name) {
48 string upper = Util::toUpper(name);
49 if (upper == "BLACK" ) return ANSI_BGCOLOR_BLACK;
50 if (upper == "RED" ) return ANSI_BGCOLOR_RED;
51 if (upper == "GREEN" ) return ANSI_BGCOLOR_GREEN;
52 if (upper == "BROWN" ) return ANSI_BGCOLOR_BROWN;
53 if (upper == "BLUE" ) return ANSI_BGCOLOR_BLUE;
54 if (upper == "MAGENTA" ) return ANSI_BGCOLOR_MAGENTA;
55 if (upper == "CYAN" ) return ANSI_BGCOLOR_CYAN;
56 if (upper == "GRAY" ) return ANSI_BGCOLOR_GRAY;
57 return nullptr;
60 void get_supported_colors(std::vector<std::string> &names) {
61 names.push_back(Util::toLower("BLACK" ));
62 names.push_back(Util::toLower("RED" ));
63 names.push_back(Util::toLower("GREEN" ));
64 names.push_back(Util::toLower("BROWN" ));
65 names.push_back(Util::toLower("BLUE" ));
66 names.push_back(Util::toLower("MAGENTA" ));
67 names.push_back(Util::toLower("CYAN" ));
68 names.push_back(Util::toLower("GRAY" ));
69 names.push_back(Util::toLower("DARK_GRAY" ));
70 names.push_back(Util::toLower("LIGHT_RED" ));
71 names.push_back(Util::toLower("LIGHT_GREEN" ));
72 names.push_back(Util::toLower("YELLOW" ));
73 names.push_back(Util::toLower("LIGHT_BLUE" ));
74 names.push_back(Util::toLower("LIGHT_MAGENTA" ));
75 names.push_back(Util::toLower("LIGHT_CYAN" ));
76 names.push_back(Util::toLower("WHITE" ));
79 std::string add_bgcolor(const char *color, const char *bgcolor) {
80 assert(color && *color && color[strlen(color) - 1] == 'm');
81 assert(bgcolor && *bgcolor);
83 string ret = color;
84 return ret.substr(0, ret.length() - 1) + bgcolor;
87 ///////////////////////////////////////////////////////////////////////////////