mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-30 20:37:20 +02:00
ViewTask
- Supports the notion of different colors for sorted columns.
This commit is contained in:
parent
489750c80a
commit
aac0753b07
2 changed files with 31 additions and 23 deletions
|
@ -41,6 +41,7 @@ ViewTask::ViewTask ()
|
||||||
: _width (0)
|
: _width (0)
|
||||||
, _left_margin (0)
|
, _left_margin (0)
|
||||||
, _header (0)
|
, _header (0)
|
||||||
|
, _sort_header (0)
|
||||||
, _odd (0)
|
, _odd (0)
|
||||||
, _even (0)
|
, _even (0)
|
||||||
, _intra_padding (1)
|
, _intra_padding (1)
|
||||||
|
@ -115,13 +116,13 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
|
||||||
|
|
||||||
bool const print_empty_columns = context.config.getBoolean ("print.empty.columns");
|
bool const print_empty_columns = context.config.getBoolean ("print.empty.columns");
|
||||||
std::vector <Column*> nonempty_columns;
|
std::vector <Column*> nonempty_columns;
|
||||||
|
std::vector <bool> nonempty_sort;
|
||||||
|
|
||||||
// Determine minimal, ideal column widths.
|
// Determine minimal, ideal column widths.
|
||||||
std::vector <int> minimal;
|
std::vector <int> minimal;
|
||||||
std::vector <int> ideal;
|
std::vector <int> ideal;
|
||||||
|
|
||||||
std::vector <Column*>::iterator i;
|
for (unsigned int i = 0; i < _columns.size (); ++i)
|
||||||
for (i = _columns.begin (); i != _columns.end (); ++i)
|
|
||||||
{
|
{
|
||||||
// Headers factor in to width calculations.
|
// Headers factor in to width calculations.
|
||||||
unsigned int global_min = 0;
|
unsigned int global_min = 0;
|
||||||
|
@ -138,7 +139,7 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
|
||||||
// Determine minimum and ideal width for this column.
|
// Determine minimum and ideal width for this column.
|
||||||
unsigned int min = 0;
|
unsigned int min = 0;
|
||||||
unsigned int ideal = 0;
|
unsigned int ideal = 0;
|
||||||
(*i)->measure (data[sequence[s]], min, ideal);
|
_columns[i]->measure (data[sequence[s]], min, ideal);
|
||||||
|
|
||||||
if (min > global_min) global_min = min;
|
if (min > global_min) global_min = min;
|
||||||
if (ideal > global_ideal) global_ideal = ideal;
|
if (ideal > global_ideal) global_ideal = ideal;
|
||||||
|
@ -146,7 +147,7 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
|
||||||
|
|
||||||
if (print_empty_columns || global_min != 0)
|
if (print_empty_columns || global_min != 0)
|
||||||
{
|
{
|
||||||
unsigned int label_length = utf8_width ((*i)->label ());
|
unsigned int label_length = utf8_width (_columns[i]->label ());
|
||||||
if (label_length > global_min) global_min = label_length;
|
if (label_length > global_min) global_min = label_length;
|
||||||
if (label_length > global_ideal) global_ideal = label_length;
|
if (label_length > global_ideal) global_ideal = label_length;
|
||||||
minimal.push_back (global_min);
|
minimal.push_back (global_min);
|
||||||
|
@ -155,12 +156,16 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
|
||||||
|
|
||||||
if (! print_empty_columns && global_min != 0)
|
if (! print_empty_columns && global_min != 0)
|
||||||
{
|
{
|
||||||
nonempty_columns.push_back (*i);
|
nonempty_columns.push_back (_columns[i]);
|
||||||
|
nonempty_sort.push_back (_sort[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! print_empty_columns)
|
if (! print_empty_columns)
|
||||||
|
{
|
||||||
_columns = nonempty_columns;
|
_columns = nonempty_columns;
|
||||||
|
_sort = nonempty_sort;
|
||||||
|
}
|
||||||
|
|
||||||
int all_extra = _left_margin
|
int all_extra = _left_margin
|
||||||
+ (2 * _extra_padding)
|
+ (2 * _extra_padding)
|
||||||
|
@ -227,7 +232,7 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
|
||||||
for (unsigned int c = 0; c < _columns.size (); ++c)
|
for (unsigned int c = 0; c < _columns.size (); ++c)
|
||||||
{
|
{
|
||||||
headers.push_back (std::vector <std::string> ());
|
headers.push_back (std::vector <std::string> ());
|
||||||
_columns[c]->renderHeader (headers[c], widths[c], _header);
|
_columns[c]->renderHeader (headers[c], widths[c], _sort[c] ? _sort_header : _header);
|
||||||
|
|
||||||
if (headers[c].size () > max_lines)
|
if (headers[c].size () > max_lines)
|
||||||
max_lines = headers[c].size ();
|
max_lines = headers[c].size ();
|
||||||
|
|
|
@ -40,33 +40,36 @@ public:
|
||||||
~ViewTask ();
|
~ViewTask ();
|
||||||
|
|
||||||
// View specifications.
|
// View specifications.
|
||||||
void add (Column* column) { _columns.push_back (column); }
|
void add (Column* column, bool sort = false) { _columns.push_back (column); _sort.push_back (sort); }
|
||||||
void width (int width) { _width = width; }
|
void width (int width) { _width = width; }
|
||||||
void leftMargin (int margin) { _left_margin = margin; }
|
void leftMargin (int margin) { _left_margin = margin; }
|
||||||
void colorHeader (Color& c) { _header = c; }
|
void colorHeader (Color& c) { _header = c; if (!_sort_header) _sort_header = c; }
|
||||||
void colorOdd (Color& c) { _odd = c; }
|
void colorSortHeader (Color& c) { _sort_header = c; }
|
||||||
void colorEven (Color& c) { _even = c; }
|
void colorOdd (Color& c) { _odd = c; }
|
||||||
void intraPadding (int padding) { _intra_padding = padding; }
|
void colorEven (Color& c) { _even = c; }
|
||||||
void intraColorOdd (Color& c) { _intra_odd = c; }
|
void intraPadding (int padding) { _intra_padding = padding; }
|
||||||
void intraColorEven (Color& c) { _intra_even = c; }
|
void intraColorOdd (Color& c) { _intra_odd = c; }
|
||||||
void extraPadding (int padding) { _extra_padding = padding; }
|
void intraColorEven (Color& c) { _intra_even = c; }
|
||||||
void extraColorOdd (Color& c) { _extra_odd = c; }
|
void extraPadding (int padding) { _extra_padding = padding; }
|
||||||
void extraColorEven (Color& c) { _extra_even = c; }
|
void extraColorOdd (Color& c) { _extra_odd = c; }
|
||||||
void truncateLines (int n) { _truncate_lines = n; }
|
void extraColorEven (Color& c) { _extra_even = c; }
|
||||||
void truncateRows (int n) { _truncate_rows = n; }
|
void truncateLines (int n) { _truncate_lines = n; }
|
||||||
void addBreak (const std::string& attr) { _breaks.push_back (attr); }
|
void truncateRows (int n) { _truncate_rows = n; }
|
||||||
int lines () { return _lines; }
|
void addBreak (const std::string& attr) { _breaks.push_back (attr); }
|
||||||
int rows () { return _rows; }
|
int lines () { return _lines; }
|
||||||
|
int rows () { return _rows; }
|
||||||
|
|
||||||
// View rendering.
|
// View rendering.
|
||||||
std::string render (std::vector <Task>&, std::vector <int>&);
|
std::string render (std::vector <Task>&, std::vector <int>&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <Column*> _columns;
|
std::vector <Column*> _columns;
|
||||||
|
std::vector <bool> _sort;
|
||||||
std::vector <std::string> _breaks;
|
std::vector <std::string> _breaks;
|
||||||
int _width;
|
int _width;
|
||||||
int _left_margin;
|
int _left_margin;
|
||||||
Color _header;
|
Color _header;
|
||||||
|
Color _sort_header;
|
||||||
Color _odd;
|
Color _odd;
|
||||||
Color _even;
|
Color _even;
|
||||||
int _intra_padding;
|
int _intra_padding;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue