166 integer_t minWidth = columnName.size() + (getConfiguration(writeTypes) ? typeCode.size() + 3 : 0); // 3 = " ()" in "columnName (typeCode)" |
161 integer_t minWidth = columnName.size() + (getConfiguration(writeTypes) ? typeCode.size() + 3 : 0); // 3 = " ()" in "columnName (typeCode)" |
167 columnWidths[i] = max(columnWidths[i], minWidth); |
162 columnWidths[i] = max(columnWidths[i], minWidth); |
168 paddings[i] = columnWidths[i] - minWidth; |
163 paddings[i] = columnWidths[i] - minWidth; |
169 } |
164 } |
170 |
165 |
171 printHorizontalLine(L"╭", L"┬", L"╮"); |
166 if (configuration.tableStyle == Configuration::TableStyle::Rounded) printHorizontalLine(L"╭", L"┬", L"╮", L"─"); |
|
167 else if (configuration.tableStyle == Configuration::TableStyle::Sharp) printHorizontalLine(L"┌", L"┬", L"┐", L"─"); |
|
168 else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) printHorizontalLine(L"╔", L"╦", L"╗", L"═"); |
|
169 else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) printHorizontalLine(L"─", L"─", L"─", L"─"); |
|
170 else if (configuration.tableStyle == Configuration::TableStyle::Ascii) printHorizontalLine(L"+", L"+", L"+", L"-"); |
|
171 else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle)); |
|
172 |
|
173 std::string verticalSeparator; |
|
174 if (configuration.tableStyle == Configuration::TableStyle::Rounded) verticalSeparator = "│"; |
|
175 else if (configuration.tableStyle == Configuration::TableStyle::Sharp) verticalSeparator = "│"; |
|
176 else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) verticalSeparator = "║"; |
|
177 else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) verticalSeparator = " "; |
|
178 else if (configuration.tableStyle == Configuration::TableStyle::Ascii) verticalSeparator = "|"; |
|
179 else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle)); |
172 |
180 |
173 // Print column headers: |
181 // Print column headers: |
174 output << INDENT << ESC_BORDER << "│" << ESC_RESET; |
182 output << INDENT << ESC_BORDER << verticalSeparator << ESC_RESET; |
175 for (size_t i = 0; i < columnCount; i++) { |
183 for (size_t i = 0; i < columnCount; i++) { |
176 output << " " << convertor.to_bytes(formatValue(columnNames[i], ESC_HEADER)); |
184 output << " " << convertor.to_bytes(formatValue(columnNames[i], ESC_HEADER)); |
177 for (integer_t p = 0; p < paddings[i]; p++) { |
185 for (integer_t p = 0; p < paddings[i]; p++) { |
178 output << " "; |
186 output << " "; |
179 } |
187 } |
180 if (getConfiguration(writeTypes)) output << " (" << convertor.to_bytes(columnTypeCodes[i]) << ")"; |
188 if (getConfiguration(writeTypes)) output << " (" << convertor.to_bytes(columnTypeCodes[i]) << ")"; |
181 output << ESC_BORDER << " │" << ESC_RESET; |
189 output << ESC_BORDER << " " << verticalSeparator << ESC_RESET; |
182 } |
190 } |
183 output << std::endl; |
191 output << std::endl; |
184 printHorizontalLine(L"├", L"┼", L"┤"); |
192 if (configuration.tableStyle == Configuration::TableStyle::Rounded) printHorizontalLine(L"├", L"┼", L"┤", L"─"); |
|
193 else if (configuration.tableStyle == Configuration::TableStyle::Sharp) printHorizontalLine(L"├", L"┼", L"┤", L"─"); |
|
194 else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) printHorizontalLine(L"╠", L"╬", L"╣", L"═"); |
|
195 else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) printHorizontalLine(L"─", L"─", L"─", L"─"); |
|
196 else if (configuration.tableStyle == Configuration::TableStyle::Ascii) printHorizontalLine(L"+", L"+", L"+", L"-"); |
|
197 else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle)); |
185 |
198 |
186 // Print particular rows: |
199 // Print particular rows: |
187 for (size_t i = 0; i < values.size(); i++) { |
200 for (size_t i = 0; i < values.size(); i++) { |
188 integer_t columnIndex = i % columnCount; |
201 integer_t columnIndex = i % columnCount; |
189 if (columnIndex == 0) output << INDENT << ESC_BORDER << "│" << ESC_RESET; |
202 if (columnIndex == 0) output << INDENT << ESC_BORDER << verticalSeparator << ESC_RESET; |
190 string_t stringValue = values[i]; |
203 string_t stringValue = values[i]; |
191 integer_t padding = columnWidths[columnIndex] - computeWidth(stringValue); |
204 integer_t padding = columnWidths[columnIndex] - computeWidth(stringValue); |
192 boolean_t alignRight = columnTypes[columnIndex] == TypeId::BOOLEAN || columnTypes[columnIndex] == TypeId::INTEGER; |
205 boolean_t alignRight = columnTypes[columnIndex] == TypeId::BOOLEAN || columnTypes[columnIndex] == TypeId::INTEGER; |
193 |
206 |
194 if (alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
207 if (alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
195 output << " " << convertor.to_bytes(formatValue(stringValue, ESC_VALUE)); |
208 output << " " << convertor.to_bytes(formatValue(stringValue, ESC_VALUE)); |
196 if (!alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
209 if (!alignRight) for (integer_t p = 0; p < padding; p++) output << " "; |
197 |
210 |
198 output << ESC_BORDER << " │" << ESC_RESET; |
211 output << ESC_BORDER << " " << verticalSeparator << ESC_RESET; |
199 if (columnIndex == (columnCount - 1)) output << std::endl; |
212 if (columnIndex == (columnCount - 1)) output << std::endl; |
200 } |
213 } |
201 printHorizontalLine(L"╰", L"┴", L"╯"); |
214 if (configuration.tableStyle == Configuration::TableStyle::Rounded) printHorizontalLine(L"╰", L"┴", L"╯", L"─"); |
|
215 else if (configuration.tableStyle == Configuration::TableStyle::Sharp) printHorizontalLine(L"└", L"┴", L"┘", L"─"); |
|
216 else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) printHorizontalLine(L"╚", L"╩", L"╝", L"═"); |
|
217 else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) printHorizontalLine(L"─", L"─", L"─", L"─"); |
|
218 else if (configuration.tableStyle == Configuration::TableStyle::Ascii) printHorizontalLine(L"+", L"+", L"+", L"-"); |
|
219 else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle)); |
202 |
220 |
203 if (getConfiguration(writeRecordCount)) { |
221 if (getConfiguration(writeRecordCount)) { |
204 integer_t recordCount = values.size() / columnCount; |
222 integer_t recordCount = values.size() / columnCount; |
205 output << ESC_YELLOW << "Record count: " << ESC_RESET << recordCount << std::endl; |
223 output << ESC_YELLOW << "Record count: " << ESC_RESET << recordCount << std::endl; |
206 } |
224 } |