MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / render

Method render

src/ViewTask.cpp:108–385  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// |<---------- terminal width ---------->| +-------+ +-------+ +-------+ |header | |header | |header | +--+--+-------+--+-------+--+-------+--+ |ma|ex|cell |in|cell |in|cell |ex| +--+--+-------+--+-------+--+-------+--+ |ma|ex|cell |in|cell |in|cell |ex| +--+--+-------+--+-------+--+-------+--+ margin

Source from the content-addressed store, hash-verified

106// field is W1, then a solution may be achievable by reducing W0 --> W1.
107//
108std::string ViewTask::render(std::vector<Task>& data, std::vector<int>& sequence) {
109 Timer timer;
110
111 bool const obfuscate = Context::getContext().config.getBoolean("obfuscate");
112 bool const print_empty_columns = Context::getContext().config.getBoolean("print.empty.columns");
113 std::vector<Column*> nonempty_columns;
114 std::vector<bool> nonempty_sort;
115
116 // Determine minimal, ideal column widths.
117 std::vector<int> minimal;
118 std::vector<int> ideal;
119
120 for (unsigned int i = 0; i < _columns.size(); ++i) {
121 // Headers factor in to width calculations.
122 unsigned int global_min = 0;
123 unsigned int global_ideal = global_min;
124
125 for (unsigned int s = 0; s < sequence.size(); ++s) {
126 if ((int)s >= _truncate_lines && _truncate_lines != 0) break;
127
128 if ((int)s >= _truncate_rows && _truncate_rows != 0) break;
129
130 // Determine minimum and ideal width for this column.
131 unsigned int min = 0;
132 unsigned int ideal = 0;
133 _columns[i]->measure(data[sequence[s]], min, ideal);
134
135 if (min > global_min) global_min = min;
136 if (ideal > global_ideal) global_ideal = ideal;
137
138 // If a fixed-width column was just measured, there is no point repeating
139 // the measurement for all tasks.
140 if (_columns[i]->is_fixed_width()) break;
141 }
142
143 if (print_empty_columns || global_min != 0) {
144 unsigned int label_length = utf8_width(_columns[i]->label());
145 if (label_length > global_min) global_min = label_length;
146 if (label_length > global_ideal) global_ideal = label_length;
147 minimal.push_back(global_min);
148 ideal.push_back(global_ideal);
149 }
150
151 if (!print_empty_columns) {
152 if (global_min != 0) // Column is nonempty
153 {
154 nonempty_columns.push_back(_columns[i]);
155 nonempty_sort.push_back(_sort[i]);
156 } else // Column is empty, drop it
157 {
158 // Note: This is safe to do because we set _columns = nonempty_columns
159 // after iteration over _columns is finished.
160 delete _columns[i];
161 }
162 }
163 }
164
165 if (!print_empty_columns) {

Callers 1

TEST_NAMEFunction · 0.45

Calls 10

autoColorizeFunction · 0.85
is_fixed_widthMethod · 0.80
errorMethod · 0.80
renderHeaderMethod · 0.80
colorMethod · 0.80
typeMethod · 0.80
clearMethod · 0.80
measureMethod · 0.45
debugMethod · 0.45
getMethod · 0.45

Tested by 1

TEST_NAMEFunction · 0.36