Feature - 256-color support

- Fixed bug that caused \033[m sequences to be emitted when no color
  is specified, in 16-color mode.
This commit is contained in:
Paul Beckingham 2009-09-22 21:36:36 -04:00
parent ff3b7cf337
commit 2074c8bb27

View file

@ -418,18 +418,35 @@ std::string Color::colorize (const std::string& input)
// 256 color
if (value & _COLOR_256)
{
bool needTerminator = false;
if (value & _COLOR_UNDERLINE)
{
result << "\033[4m";
needTerminator = true;
}
if (!(value & _COLOR_NOFG))
{
result << "\033[38;5;" << (value & _COLOR_FG) << "m";
needTerminator = true;
}
if (!(value & _COLOR_NOBG))
{
result << "\033[48;5;" << ((value & _COLOR_BG) >> 8) << "m";
needTerminator = true;
}
result << input;
if (needTerminator)
result << "\033[0m";
return result.str ();
}
// 16 color
else
if (value != (_COLOR_NOFG | _COLOR_NOBG))
{
result << "\033[";
@ -457,11 +474,11 @@ std::string Color::colorize (const std::string& input)
result << (29 + (value & _COLOR_FG));
}
result << "m";
result << "m" << input << "\033[0m";
return result.str ();
}
result << input << "\033[0m";
return result.str ();
return input;
}
////////////////////////////////////////////////////////////////////////////////