equal
deleted
inserted
replaced
96 result << convertor.from_bytes(ESC_RESET); |
96 result << convertor.from_bytes(ESC_RESET); |
97 |
97 |
98 return result.str(); |
98 return result.str(); |
99 } |
99 } |
100 |
100 |
|
101 /** |
|
102 * @param stringValue |
|
103 * @return the width that would the string occupy on the display (particular characters might be wider than 1 column) |
|
104 */ |
|
105 integer_t computeWidth(const string_t& stringValue) { |
|
106 integer_t width = 0; |
|
107 for (wchar_t ch : stringValue) width += std::max(0, wcwidth(ch)); |
|
108 return width; |
|
109 } |
|
110 |
101 void printHorizontalLine(const string_t &left, const string_t &middle, const string_t &right) { |
111 void printHorizontalLine(const string_t &left, const string_t &middle, const string_t &right) { |
102 const string_t bar = L"─"; |
112 const string_t bar = L"─"; |
103 // TODO: support also ASCII nostalgia: |
113 // TODO: support also ASCII nostalgia: |
104 // border = border.replaceAll("─", "-"); |
114 // border = border.replaceAll("─", "-"); |
105 // border = border.replaceAll("│", "|"); |
115 // border = border.replaceAll("│", "|"); |
146 // Print particular rows: |
156 // Print particular rows: |
147 for (size_t i = 0; i < values.size(); i++) { |
157 for (size_t i = 0; i < values.size(); i++) { |
148 integer_t columnIndex = i % columnCount; |
158 integer_t columnIndex = i % columnCount; |
149 if (columnIndex == 0) output << INDENT << ESC_BORDER << "│" << ESC_RESET; |
159 if (columnIndex == 0) output << INDENT << ESC_BORDER << "│" << ESC_RESET; |
150 string_t stringValue = values[i]; |
160 string_t stringValue = values[i]; |
151 integer_t padding = columnWidths[columnIndex] - stringValue.size(); |
161 integer_t padding = columnWidths[columnIndex] - computeWidth(stringValue); |
152 boolean_t alignRight = columnTypes[columnIndex] == TypeId::BOOLEAN || columnTypes[columnIndex] == TypeId::INTEGER; |
162 boolean_t alignRight = columnTypes[columnIndex] == TypeId::BOOLEAN || columnTypes[columnIndex] == TypeId::INTEGER; |
153 |
163 |
154 if (alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
164 if (alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
155 output << " " << convertor.to_bytes(formatValue(stringValue, ESC_VALUE)); |
165 output << " " << convertor.to_bytes(formatValue(stringValue, ESC_VALUE)); |
156 if (!alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
166 if (!alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
188 } |
198 } |
189 |
199 |
190 void attribute(const string_t& value) override { |
200 void attribute(const string_t& value) override { |
191 integer_t i = values.size() % columnCount; |
201 integer_t i = values.size() % columnCount; |
192 values.push_back(value); |
202 values.push_back(value); |
193 columnWidths[i] = max(columnWidths[i], value.length()); |
203 columnWidths[i] = max(columnWidths[i], computeWidth(value)); |
194 } |
204 } |
195 |
205 |
196 void endOfPipe() { |
206 void endOfPipe() { |
197 if (columnCount) printCachedData(); |
207 if (columnCount) printCachedData(); |
198 } |
208 } |