This commit is contained in:
Your Name
2025-04-21 20:56:54 +12:00
parent b135bed29c
commit 749efef29d
3 changed files with 28 additions and 3 deletions

View File

@ -4,13 +4,17 @@
#include <locale>
#include <cwchar>
tableprint::tableprint() {
tableprint::tableprint(const std::string title) : title(title) {
// Set locale for wide character support
std::setlocale(LC_ALL, "");
}
tableprint::~tableprint() {}
void tableprint::set_title(const std::string title) {
this->title = title;
}
void tableprint::add_row(const std::vector<std::string>& row) {
rows.push_back(row);
}
@ -26,6 +30,25 @@ void tableprint::print() {
}
}
// Calculate total table width
size_t total_width = 0;
for (size_t width : col_widths) {
total_width += width + 2; // +2 for padding
}
total_width += col_widths.size() - 1; // Add space for vertical borders
// Print title if it exists
if (!title.empty()) {
std::wcout << L"\033[90m"; // Dark grey color for borders
std::wcout << L"" << std::wstring(total_width, L'') << L"" << std::endl;
std::wcout << L"" << L"\033[1;37m"; // White color for title
size_t padding = (total_width - title.length()) / 2;
std::wcout << std::wstring(padding, L' ') << std::wstring(title.begin(), title.end())
<< std::wstring(total_width - title.length() - padding, L' ');
std::wcout << L"\033[90m│" << std::endl;
std::wcout << L"" << std::wstring(total_width, L'') << L"" << std::endl;
}
// Print top border
std::wcout << L"\033[90m"; // Dark grey color for borders
std::wcout << L"";