--- a/src/TabularPrefetchingHandler.h Mon Jun 20 00:15:08 2022 +0200
+++ b/src/TabularPrefetchingHandler.h Mon Jun 20 00:55:56 2022 +0200
@@ -28,6 +28,7 @@
#include <relpipe/reader/TypeId.h>
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
#include <relpipe/reader/handlers/AttributeMetadata.h>
+#include <relpipe/reader/RelpipeReaderException.h>
#include "Configuration.h"
@@ -138,13 +139,7 @@
return width;
}
- void printHorizontalLine(const string_t &left, const string_t &middle, const string_t &right) {
- const string_t bar = L"─";
- // TODO: support also ASCII nostalgia:
- // border = border.replaceAll("─", "-");
- // border = border.replaceAll("│", "|");
- // border = border.replaceAll("[╭┬╮├┼┤╰┴╯]", "+");
-
+ void printHorizontalLine(const string_t& left, const string_t& middle, const string_t& right, const string_t& bar) {
output << INDENT << ESC_BORDER;
output << convertor.to_bytes(left);
for (size_t c = 0; c < columnCount; c++) {
@@ -168,25 +163,43 @@
paddings[i] = columnWidths[i] - minWidth;
}
- printHorizontalLine(L"╭", L"┬", L"╮");
+ if (configuration.tableStyle == Configuration::TableStyle::Rounded) printHorizontalLine(L"╭", L"┬", L"╮", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::Sharp) printHorizontalLine(L"┌", L"┬", L"┐", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) printHorizontalLine(L"╔", L"╦", L"╗", L"═");
+ else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) printHorizontalLine(L"─", L"─", L"─", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::Ascii) printHorizontalLine(L"+", L"+", L"+", L"-");
+ else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle));
+
+ std::string verticalSeparator;
+ if (configuration.tableStyle == Configuration::TableStyle::Rounded) verticalSeparator = "│";
+ else if (configuration.tableStyle == Configuration::TableStyle::Sharp) verticalSeparator = "│";
+ else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) verticalSeparator = "║";
+ else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) verticalSeparator = " ";
+ else if (configuration.tableStyle == Configuration::TableStyle::Ascii) verticalSeparator = "|";
+ else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle));
// Print column headers:
- output << INDENT << ESC_BORDER << "│" << ESC_RESET;
+ output << INDENT << ESC_BORDER << verticalSeparator << ESC_RESET;
for (size_t i = 0; i < columnCount; i++) {
output << " " << convertor.to_bytes(formatValue(columnNames[i], ESC_HEADER));
for (integer_t p = 0; p < paddings[i]; p++) {
output << " ";
}
if (getConfiguration(writeTypes)) output << " (" << convertor.to_bytes(columnTypeCodes[i]) << ")";
- output << ESC_BORDER << " │" << ESC_RESET;
+ output << ESC_BORDER << " " << verticalSeparator << ESC_RESET;
}
output << std::endl;
- printHorizontalLine(L"├", L"┼", L"┤");
+ if (configuration.tableStyle == Configuration::TableStyle::Rounded) printHorizontalLine(L"├", L"┼", L"┤", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::Sharp) printHorizontalLine(L"├", L"┼", L"┤", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) printHorizontalLine(L"╠", L"╬", L"╣", L"═");
+ else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) printHorizontalLine(L"─", L"─", L"─", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::Ascii) printHorizontalLine(L"+", L"+", L"+", L"-");
+ else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle));
// Print particular rows:
for (size_t i = 0; i < values.size(); i++) {
integer_t columnIndex = i % columnCount;
- if (columnIndex == 0) output << INDENT << ESC_BORDER << "│" << ESC_RESET;
+ if (columnIndex == 0) output << INDENT << ESC_BORDER << verticalSeparator << ESC_RESET;
string_t stringValue = values[i];
integer_t padding = columnWidths[columnIndex] - computeWidth(stringValue);
boolean_t alignRight = columnTypes[columnIndex] == TypeId::BOOLEAN || columnTypes[columnIndex] == TypeId::INTEGER;
@@ -195,10 +208,15 @@
output << " " << convertor.to_bytes(formatValue(stringValue, ESC_VALUE));
if (!alignRight) for (integer_t p = 0; p < padding; p++) output << " ";
- output << ESC_BORDER << " │" << ESC_RESET;
+ output << ESC_BORDER << " " << verticalSeparator << ESC_RESET;
if (columnIndex == (columnCount - 1)) output << std::endl;
}
- printHorizontalLine(L"╰", L"┴", L"╯");
+ if (configuration.tableStyle == Configuration::TableStyle::Rounded) printHorizontalLine(L"╰", L"┴", L"╯", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::Sharp) printHorizontalLine(L"└", L"┴", L"┘", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::SharpDouble) printHorizontalLine(L"╚", L"╩", L"╝", L"═");
+ else if (configuration.tableStyle == Configuration::TableStyle::HorizontalOnly) printHorizontalLine(L"─", L"─", L"─", L"─");
+ else if (configuration.tableStyle == Configuration::TableStyle::Ascii) printHorizontalLine(L"+", L"+", L"+", L"-");
+ else throw RelpipeReaderException(L"Unsupported TableStyle: " + std::to_wstring((int) configuration.tableStyle));
if (getConfiguration(writeRecordCount)) {
integer_t recordCount = values.size() / columnCount;