1 #include <Interface/Colors.hpp> 5 bool Colors::hasColors =
false;
9 if (has_colors() != TRUE)
11 Colors::hasColors =
false;
14 Colors::hasColors =
true;
40 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++)
42 for (j = COLOR_BLACK; j <= COLOR_WHITE; j++)
59 if (use_default_colors() != ERR)
62 init_pair(64, COLOR_BLACK, COLOR_DEFAULT);
63 init_pair(65, COLOR_RED, COLOR_DEFAULT);
64 init_pair(66, COLOR_GREEN, COLOR_DEFAULT);
65 init_pair(67, COLOR_YELLOW, COLOR_DEFAULT);
66 init_pair(68, COLOR_BLUE, COLOR_DEFAULT);
67 init_pair(69, COLOR_MAGENTA, COLOR_DEFAULT);
68 init_pair(70, COLOR_CYAN, COLOR_DEFAULT);
69 init_pair(71, COLOR_WHITE, COLOR_DEFAULT);
74 Color Colors::rgb(
short r,
short g,
short b)
76 if (can_change_color() == FALSE)
82 static int color_no = 8;
84 if (color_no >= COLORS)
88 int expand = 1000/255;
90 init_color((color_no - 1), r*expand, g*expand, b*expand);
91 return (color_no - 1);
93 Color Colors::hex(std::string hex)
95 if (hex[0] !=
'#')
return 0;
96 if (hex.size() != 7)
return 0;
103 long r = strtol(col, NULL, 16);
107 long g = strtol(col, NULL, 16);
111 long b = strtol(col, NULL, 16);
113 return Colors::rgb(r, g, b);
116 ColorPair Colors::pair(Color foreground, Color background,
bool is_bold)
119 if ((foreground < 8) && (background < 8))
121 if (background == COLOR_DEFAULT)
124 return COLOR_PAIR(64 + foreground) | A_BOLD;
126 return COLOR_PAIR(64 + foreground);
130 return COLOR_PAIR(foreground*8 + background + 1) | A_BOLD;
132 return COLOR_PAIR(foreground*8 + background + 1);
138 return COLOR_PAIR(0) | A_BOLD;
140 return COLOR_PAIR(0);
145 static int color_pair_no = 72;
147 if (color_pair_no >= COLOR_PAIRS)
150 init_pair((color_pair_no - 1), foreground, background);
153 return COLOR_PAIR(color_pair_no - 1) | A_BOLD;
155 return COLOR_PAIR(color_pair_no - 1);
157 Color Colors::fromString(std::string str)
162 if (str ==
"default")
return COLOR_DEFAULT;
163 if (str ==
"black")
return COLOR_BLACK;
164 if (str ==
"red")
return COLOR_RED;
165 if (str ==
"green")
return COLOR_GREEN;
166 if (str ==
"yellow")
return COLOR_YELLOW;
167 if (str ==
"blue")
return COLOR_BLUE;
168 if (str ==
"magenta")
return COLOR_MAGENTA;
169 if (str ==
"cyan")
return COLOR_CYAN;
170 if (str ==
"white")
return COLOR_WHITE;
176 ColorPair Colors::pairFromString(std::string foreground, std::string background,
bool is_bold)
178 if (foreground.empty() || background.empty())
181 short f = Colors::fromString(foreground);
182 short b = Colors::fromString(background);
184 return Colors::pair(f, b, is_bold);
187 void Colors::activate(WINDOW* window, Color foreground, Color background)
189 Colors::pairActivate(window, Colors::pair(foreground, background));
192 void Colors::pairActivate(WINDOW* window, ColorPair color)
194 wattrset(window, color);