- Corrected colorization rules parsing.

This commit is contained in:
Paul Beckingham 2008-05-13 23:38:22 -04:00
parent 494ed3b964
commit 2ecf500322
2 changed files with 12 additions and 32 deletions

View file

@ -11,6 +11,9 @@
------ reality -----------------------------------
0.9.6
5/13/208
+ Replaced color management code.
+ Improved color rules code.
0.9.5
5/12/2008

View file

@ -16,8 +16,8 @@ static std::map <std::string, Text::color> gsBg;
////////////////////////////////////////////////////////////////////////////////
// There are three supported variants:
// 1) "fg"
// 2) "on bg"
// 3) "fg on bg"
// 2) "bg"
// 3) "fg bg"
static void parseColorRule (
const std::string& rule,
Text::color& fg,
@ -25,41 +25,18 @@ static void parseColorRule (
{
fg = Text::nocolor;
bg = Text::nocolor;
bool error = false;
std::vector <std::string> words;
split (words, rule, ' ');
switch (words.size ())
std::vector <std::string>::iterator it;
for (it = words.begin (); it != words.end (); ++it)
{
case 1: // "fg" - no spaces.
fg = Text::colorCode (words[0]);
break;
case 2: // "on bg" - one space, "on" before.
if (words[0] == "on")
bg = Text::colorCode (words[1]);
if (it->substr (0, 3) == "on_")
bg = Text::colorCode (*it);
else
error = true;
break;
case 3: // "fg on bg" - two spaces, "on" between them.
if (words[1] == "on")
{
fg = Text::colorCode (words[0]);
bg = Text::colorCode (words[2]);
fg = Text::colorCode (*it);
}
else
error = true;
break;
case 0:
default:
error = true;
break;
}
if (error)
std::cout << "Malformed color rule '" << rule << "'" << std::endl;
}
////////////////////////////////////////////////////////////////////////////////