Code Cleanup

- All objects now use the same convention for naming members.  The
  consistency is a good thing.
This commit is contained in:
Paul Beckingham 2011-08-25 21:54:28 -04:00
parent fb6dc5058f
commit dab06f8672
53 changed files with 1347 additions and 1349 deletions

View file

@ -62,26 +62,26 @@ static struct
////////////////////////////////////////////////////////////////////////////////
Color::Color ()
: value (0)
: _value (0)
{
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (const Color& other)
{
value = other.value;
_value = other._value;
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (unsigned int c)
: value (0)
: _value (0)
{
if (!(c & _COLOR_HASFG)) value &= ~_COLOR_FG;
if (!(c & _COLOR_HASBG)) value &= ~_COLOR_BG;
if (!(c & _COLOR_HASFG)) _value &= ~_COLOR_FG;
if (!(c & _COLOR_HASBG)) _value &= ~_COLOR_BG;
value = c & (_COLOR_256 | _COLOR_HASBG | _COLOR_HASFG |_COLOR_UNDERLINE |
_COLOR_INVERSE | _COLOR_BOLD | _COLOR_BRIGHT | _COLOR_BG |
_COLOR_FG);
_value = c & (_COLOR_256 | _COLOR_HASBG | _COLOR_HASFG |_COLOR_UNDERLINE |
_COLOR_INVERSE | _COLOR_BOLD | _COLOR_BRIGHT | _COLOR_BG |
_COLOR_FG);
}
////////////////////////////////////////////////////////////////////////////////
@ -97,7 +97,7 @@ Color::Color (unsigned int c)
// colorN 0 <= N <= 255 fg 38;5;N bg 48;5;N
// rgbRGB 0 <= R,G,B <= 5 fg 38;5;16 + R*36 + G*6 + B bg 48;5;16 + R*36 + G*6 + B
Color::Color (const std::string& spec)
: value (0)
: _value (0)
{
// By converting underscores to spaces, we inherently support the old "on_red"
// style of specifying background colors. We consider underscores to be
@ -228,56 +228,56 @@ Color::Color (const std::string& spec)
}
// Now combine the fg and bg into a single color.
value = fg_value;
_value = fg_value;
blend (Color (bg_value));
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (color_id fg)
: value (0)
: _value (0)
{
if (fg != Color::nocolor)
{
value |= _COLOR_HASFG;
value |= fg;
_value |= _COLOR_HASFG;
_value |= fg;
}
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (color_id fg, color_id bg)
: value (0)
: _value (0)
{
if (bg != Color::nocolor)
{
value |= _COLOR_HASBG;
value |= (bg << 8);
_value |= _COLOR_HASBG;
_value |= (bg << 8);
}
if (fg != Color::nocolor)
{
value |= _COLOR_HASFG;
value |= fg;
_value |= _COLOR_HASFG;
_value |= fg;
}
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (color_id fg, color_id bg, bool underline, bool bold, bool bright)
: value (0)
: _value (0)
{
value |= ((underline ? 1 : 0) << 18)
| ((bold ? 1 : 0) << 17)
| ((bright ? 1 : 0) << 16);
_value |= ((underline ? 1 : 0) << 18)
| ((bold ? 1 : 0) << 17)
| ((bright ? 1 : 0) << 16);
if (bg != Color::nocolor)
{
value |= _COLOR_HASBG;
value |= (bg << 8);
_value |= _COLOR_HASBG;
_value |= (bg << 8);
}
if (fg != Color::nocolor)
{
value |= _COLOR_HASFG;
value |= fg;
_value |= _COLOR_HASFG;
_value |= fg;
}
}
@ -290,7 +290,7 @@ Color::~Color ()
Color& Color::operator= (const Color& other)
{
if (this != &other)
value = other.value;
_value = other._value;
return *this;
}
@ -299,22 +299,22 @@ Color& Color::operator= (const Color& other)
Color::operator std::string () const
{
std::string description;
if (value & _COLOR_BOLD) description += "bold";
if (_value & _COLOR_BOLD) description += "bold";
if (value & _COLOR_UNDERLINE)
if (_value & _COLOR_UNDERLINE)
description += std::string (description.length () ? " " : "") + "underline";
if (value & _COLOR_INVERSE)
if (_value & _COLOR_INVERSE)
description += std::string (description.length () ? " " : "") + "inverse";
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
description += std::string (description.length () ? " " : "") + fg ();
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
description += std::string (description.length () ? " " : "") + "on";
if (value & _COLOR_BRIGHT)
if (_value & _COLOR_BRIGHT)
description += std::string (description.length () ? " " : "") + "bright";
description += " " + bg ();
@ -326,7 +326,7 @@ Color::operator std::string () const
////////////////////////////////////////////////////////////////////////////////
Color::operator int () const
{
return (int) value;
return (int) _value;
}
////////////////////////////////////////////////////////////////////////////////
@ -335,28 +335,28 @@ Color::operator int () const
void Color::blend (const Color& other)
{
Color c (other);
value |= (c.value & _COLOR_UNDERLINE); // Always inherit underline.
value |= (c.value & _COLOR_INVERSE); // Always inherit inverse.
_value |= (c._value & _COLOR_UNDERLINE); // Always inherit underline.
_value |= (c._value & _COLOR_INVERSE); // Always inherit inverse.
// 16 <-- 16.
if (!(value & _COLOR_256) &&
!(c.value & _COLOR_256))
if (!(_value & _COLOR_256) &&
!(c._value & _COLOR_256))
{
value |= (c.value & _COLOR_BOLD); // Inherit bold.
value |= (c.value & _COLOR_BRIGHT); // Inherit bright.
_value |= (c._value & _COLOR_BOLD); // Inherit bold.
_value |= (c._value & _COLOR_BRIGHT); // Inherit bright.
if (c.value & _COLOR_HASFG)
if (c._value & _COLOR_HASFG)
{
value |= _COLOR_HASFG; // There is now a color.
value &= ~_COLOR_FG; // Remove previous color.
value |= (c.value & _COLOR_FG); // Apply other color.
_value |= _COLOR_HASFG; // There is now a color.
_value &= ~_COLOR_FG; // Remove previous color.
_value |= (c._value & _COLOR_FG); // Apply other color.
}
if (c.value & _COLOR_HASBG)
if (c._value & _COLOR_HASBG)
{
value |= _COLOR_HASBG; // There is now a color.
value &= ~_COLOR_BG; // Remove previous color.
value |= (c.value & _COLOR_BG); // Apply other color.
_value |= _COLOR_HASBG; // There is now a color.
_value &= ~_COLOR_BG; // Remove previous color.
_value |= (c._value & _COLOR_BG); // Apply other color.
}
return;
@ -364,22 +364,22 @@ void Color::blend (const Color& other)
else
{
// Upgrade either color, if necessary.
if (!(value & _COLOR_256)) upgrade ();
if (!(c.value & _COLOR_256)) c.upgrade ();
if (!(_value & _COLOR_256)) upgrade ();
if (!(c._value & _COLOR_256)) c.upgrade ();
// 256 <-- 256.
if (c.value & _COLOR_HASFG)
if (c._value & _COLOR_HASFG)
{
value |= _COLOR_HASFG; // There is now a color.
value &= ~_COLOR_FG; // Remove previous color.
value |= (c.value & _COLOR_FG); // Apply other color.
_value |= _COLOR_HASFG; // There is now a color.
_value &= ~_COLOR_FG; // Remove previous color.
_value |= (c._value & _COLOR_FG); // Apply other color.
}
if (c.value & _COLOR_HASBG)
if (c._value & _COLOR_HASBG)
{
value |= _COLOR_HASBG; // There is now a color.
value &= ~_COLOR_BG; // Remove previous color.
value |= (c.value & _COLOR_BG); // Apply other color.
_value |= _COLOR_HASBG; // There is now a color.
_value &= ~_COLOR_BG; // Remove previous color.
_value |= (c._value & _COLOR_BG); // Apply other color.
}
}
}
@ -387,27 +387,27 @@ void Color::blend (const Color& other)
////////////////////////////////////////////////////////////////////////////////
void Color::upgrade ()
{
if (!(value & _COLOR_256))
if (!(_value & _COLOR_256))
{
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
bool bold = value & _COLOR_BOLD;
unsigned int fg = value & _COLOR_FG;
value &= ~_COLOR_FG;
value &= ~_COLOR_BOLD;
value |= (bold ? fg + 7 : fg - 1);
bool bold = _value & _COLOR_BOLD;
unsigned int fg = _value & _COLOR_FG;
_value &= ~_COLOR_FG;
_value &= ~_COLOR_BOLD;
_value |= (bold ? fg + 7 : fg - 1);
}
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
bool bright = value & _COLOR_BRIGHT;
unsigned int bg = (value & _COLOR_BG) >> 8;
value &= ~_COLOR_BG;
value &= ~_COLOR_BRIGHT;
value |= (bright ? bg + 7 : bg - 1) << 8;
bool bright = _value & _COLOR_BRIGHT;
unsigned int bg = (_value & _COLOR_BG) >> 8;
_value &= ~_COLOR_BG;
_value &= ~_COLOR_BRIGHT;
_value |= (bright ? bg + 7 : bg - 1) << 8;
}
value |= _COLOR_256;
_value |= _COLOR_256;
}
}
@ -425,38 +425,38 @@ void Color::upgrade ()
// 256 bg \033[48;5;Nm
std::string Color::colorize (const std::string& input)
{
if (value == 0)
if (_value == 0)
return input;
int count = 0;
std::stringstream result;
// 256 color
if (value & _COLOR_256)
if (_value & _COLOR_256)
{
bool needTerminator = false;
if (value & _COLOR_UNDERLINE)
if (_value & _COLOR_UNDERLINE)
{
result << "\033[4m";
needTerminator = true;
}
if (value & _COLOR_INVERSE)
if (_value & _COLOR_INVERSE)
{
result << "\033[7m";
needTerminator = true;
}
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
result << "\033[38;5;" << (value & _COLOR_FG) << "m";
result << "\033[38;5;" << (_value & _COLOR_FG) << "m";
needTerminator = true;
}
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
result << "\033[48;5;" << ((value & _COLOR_BG) >> 8) << "m";
result << "\033[48;5;" << ((_value & _COLOR_BG) >> 8) << "m";
needTerminator = true;
}
@ -468,38 +468,38 @@ std::string Color::colorize (const std::string& input)
}
// 16 color
if (value != 0)
if (_value != 0)
{
result << "\033[";
if (value & _COLOR_BOLD)
if (_value & _COLOR_BOLD)
{
if (count++) result << ";";
result << "1";
}
if (value & _COLOR_UNDERLINE)
if (_value & _COLOR_UNDERLINE)
{
if (count++) result << ";";
result << "4";
}
if (value & _COLOR_INVERSE)
if (_value & _COLOR_INVERSE)
{
if (count++) result << ";";
result << "7";
}
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
if (count++) result << ";";
result << (29 + (value & _COLOR_FG));
result << (29 + (_value & _COLOR_FG));
}
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
if (count++) result << ";";
result << ((value & _COLOR_BRIGHT ? 99 : 39) + ((value & _COLOR_BG) >> 8));
result << ((_value & _COLOR_BRIGHT ? 99 : 39) + ((_value & _COLOR_BG) >> 8));
}
result << "m" << input << "\033[0m";
@ -545,7 +545,7 @@ std::string Color::colorize (const std::string& input, const std::string& spec)
////////////////////////////////////////////////////////////////////////////////
bool Color::nontrivial ()
{
return value != 0 ? true : false;
return _value != 0 ? true : false;
}
////////////////////////////////////////////////////////////////////////////////
@ -561,14 +561,14 @@ int Color::find (const std::string& input)
////////////////////////////////////////////////////////////////////////////////
std::string Color::fg () const
{
int index = value & _COLOR_FG;
int index = _value & _COLOR_FG;
if (value & _COLOR_256)
if (_value & _COLOR_256)
{
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
std::stringstream s;
s << "color" << (value & _COLOR_FG);
s << "color" << (_value & _COLOR_FG);
return s.str ();
}
}
@ -585,14 +585,14 @@ std::string Color::fg () const
////////////////////////////////////////////////////////////////////////////////
std::string Color::bg () const
{
int index = (value & _COLOR_BG) >> 8;
int index = (_value & _COLOR_BG) >> 8;
if (value & _COLOR_256)
if (_value & _COLOR_256)
{
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
std::stringstream s;
s << "color" << ((value & _COLOR_BG) >> 8);
s << "color" << ((_value & _COLOR_BG) >> 8);
return s.str ();
}
}