mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Color - Inverse
- Added support for the 'inverse' color attribute. Documentation still needs to be updated. Thanks to David Patrick.
This commit is contained in:
parent
06cab5a1ca
commit
9c53810d3e
3 changed files with 35 additions and 3 deletions
|
@ -77,7 +77,8 @@ Color::Color (unsigned int c)
|
|||
if (!(c & _COLOR_HASBG)) value &= ~_COLOR_BG;
|
||||
|
||||
value = c & (_COLOR_256 | _COLOR_HASBG | _COLOR_HASFG |_COLOR_UNDERLINE |
|
||||
_COLOR_BOLD | _COLOR_BRIGHT | _COLOR_BG | _COLOR_FG);
|
||||
_COLOR_INVERSE | _COLOR_BOLD | _COLOR_BRIGHT | _COLOR_BG |
|
||||
_COLOR_FG);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -122,6 +123,7 @@ Color::Color (const std::string& spec)
|
|||
if (word == "bold") fg_value |= _COLOR_BOLD;
|
||||
else if (word == "bright") bg_value |= _COLOR_BRIGHT;
|
||||
else if (word == "underline") fg_value |= _COLOR_UNDERLINE;
|
||||
else if (word == "inverse") fg_value |= _COLOR_INVERSE;
|
||||
else if (word == "on") bg = true;
|
||||
|
||||
// X where X is one of black, red, blue ...
|
||||
|
@ -299,6 +301,9 @@ Color::operator std::string () const
|
|||
if (value & _COLOR_UNDERLINE)
|
||||
description += std::string (description.length () ? " " : "") + "underline";
|
||||
|
||||
if (value & _COLOR_INVERSE)
|
||||
description += std::string (description.length () ? " " : "") + "inverse";
|
||||
|
||||
if (value & _COLOR_HASFG)
|
||||
description += std::string (description.length () ? " " : "") + fg ();
|
||||
|
||||
|
@ -328,6 +333,7 @@ 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.
|
||||
|
||||
// 16 <-- 16.
|
||||
if (!(value & _COLOR_256) &&
|
||||
|
@ -433,6 +439,12 @@ std::string Color::colorize (const std::string& input)
|
|||
needTerminator = true;
|
||||
}
|
||||
|
||||
if (value & _COLOR_INVERSE)
|
||||
{
|
||||
result << "\033[7m";
|
||||
needTerminator = true;
|
||||
}
|
||||
|
||||
if (value & _COLOR_HASFG)
|
||||
{
|
||||
result << "\033[38;5;" << (value & _COLOR_FG) << "m";
|
||||
|
@ -469,6 +481,12 @@ std::string Color::colorize (const std::string& input)
|
|||
result << "4";
|
||||
}
|
||||
|
||||
if (value & _COLOR_INVERSE)
|
||||
{
|
||||
if (count++) result << ";";
|
||||
result << "7";
|
||||
}
|
||||
|
||||
if (value & _COLOR_HASFG)
|
||||
{
|
||||
if (count++) result << ";";
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <string>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#define _COLOR_INVERSE 0x00400000 // Inverse attribute.
|
||||
#define _COLOR_256 0x00200000 // 256-color mode.
|
||||
#define _COLOR_HASBG 0x00100000 // Has background color (all values taken).
|
||||
#define _COLOR_HASFG 0x00080000 // Has foreground color (all values taken).
|
||||
|
@ -46,7 +47,7 @@ public:
|
|||
|
||||
Color ();
|
||||
Color (const Color&);
|
||||
Color (unsigned int); // 256 | UNDERLINE | BOLD | BRIGHT | (BG << 8) | FG
|
||||
Color (unsigned int); // 256 | INVERSE | UNDERLINE | BOLD | BRIGHT | (BG << 8) | FG
|
||||
Color (const std::string&); // "red on bright black"
|
||||
Color (color_id); // fg.
|
||||
Color (color_id, color_id); // fg, bg.
|
||||
|
|
15
src/View.cpp
15
src/View.cpp
|
@ -87,11 +87,17 @@ View::View ()
|
|||
// Note: a possible enhancement is to proportionally distribute the overage
|
||||
// according to average data length.
|
||||
//
|
||||
// Note: an enhancement to the 'no solution' problem is to simply force-break
|
||||
// the larger fields. If the widest field is W0, and the second widest
|
||||
// field is W1, then a solution may be achievable by reducing W0 --> W1.
|
||||
//
|
||||
std::string View::render (std::vector <Task>& data, std::vector <int>& sequence)
|
||||
{
|
||||
// Determine minimal, ideal column widths.
|
||||
std::vector <int> minimal;
|
||||
std::vector <int> ideal;
|
||||
// std::vector <int> avg_ideal;
|
||||
// int cumulative_ideal = 0;
|
||||
|
||||
std::vector <Column*>::iterator i;
|
||||
for (i = _columns.begin (); i != _columns.end (); ++i)
|
||||
|
@ -108,12 +114,19 @@ std::string View::render (std::vector <Task>& data, std::vector <int>& sequence)
|
|||
int ideal;
|
||||
(*i)->measure (*d, min, ideal);
|
||||
|
||||
if (min > global_min) global_min = min;
|
||||
if (min > global_min) global_min = min;
|
||||
if (ideal > global_ideal) global_ideal = ideal;
|
||||
|
||||
// cumulative_ideal += ideal;
|
||||
}
|
||||
|
||||
minimal.push_back (global_min);
|
||||
ideal.push_back (global_ideal);
|
||||
|
||||
// if (data.size ())
|
||||
// avg_ideal.push_back ((int) (cumulative_ideal / data.size ()));
|
||||
// else
|
||||
// avg_ideal.push_back (0);
|
||||
}
|
||||
|
||||
// Sum the minimal widths.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue