This commit is contained in:
Your Name
2025-04-22 23:19:16 +12:00
parent 635a7c79ec
commit caf1e87718
4 changed files with 255 additions and 48 deletions

View File

@ -29,12 +29,12 @@ struct coloredText {
};
const std::map<std::string, coloredText> kReplacements = {
{":tick:", {"", kTextColor_Green}},
{":cross:", {"", kTextColor_Red}},
{":warning:", {"⚠️", kTextColor_Yellow}},
{":info:", {"", kTextColor_Blue}},
{":check:", {"", kTextColor_Green}},
{":x:", {"", kTextColor_Red}}
{":tick:", {"+", kTextColor_Green}},
{":cross:", {"x", kTextColor_Red}},
{":warning:", {"!", kTextColor_Yellow}},
{":info:", {"i", kTextColor_Blue}},
{":check:", {"+", kTextColor_Green}},
{":x:", {"x", kTextColor_Red}}
};
// Helper function to get ANSI color code
@ -192,14 +192,14 @@ void tableprint::print() {
// Print title if it exists
if (!title.empty()) {
std::cout << "\033[90m"; // Dark grey color for borders
std::cout << "";
std::cout << "+";
for (size_t i = 0; i < rows[0].size(); ++i) {
std::cout << std::string(col_widths[i] + 2, '-');
if (i < rows[0].size() - 1) std::cout << "";
if (i < rows[0].size() - 1) std::cout << "+";
}
std::cout << "" << std::endl;
std::cout << "+" << std::endl;
std::cout << ""; // White color for title
std::cout << "|"; // White color for title
size_t title_width = 0;
for (size_t width : col_widths) {
title_width += width + 2; // +2 for padding
@ -207,82 +207,82 @@ void tableprint::print() {
title_width += col_widths.size() - 1; // Add space for vertical borders
std::cout << width_print_centered(title,title_width,"\033[1;37m");
std::cout << "\033[90m" << std::endl;
std::cout << "\033[90m|" << std::endl;
// Use └─┴─┘ for bottom of title box to connect with table
std::cout << "";
std::cout << "+";
for (size_t i = 0; i < rows[0].size(); ++i) {
std::cout << std::string(col_widths[i] + 2, '-');
if (i < rows[0].size() - 1) std::cout << "";
if (i < rows[0].size() - 1) std::cout << "-";
}
std::cout << "" << std::endl;
std::cout << "+" << std::endl;
} else {
// Print top border if no title
std::cout << "\033[90m"; // Dark grey color for borders
std::cout << "";
for (size_t i = 0; i < rows[0].size(); ++i) {
std::cout << std::string(col_widths[i] + 2, '-');
if (i < rows[0].size() - 1) std::cout << "";
if (i < rows[0].size() - 1) std::cout << "+";
}
std::cout << "" << std::endl;
std::cout << "+" << std::endl;
}
// Print header
std::cout << "";
std::cout << "|";
for (size_t i = 0; i < rows[0].size(); ++i) {
std::cout << width_print_centered(rows[0][i],col_widths[i]+2,"\033[1;36m");
if (i < rows[0].size() - 1) {
std::cout << "\033[90m\033[1;36m"; // Border color then back to cyan
std::cout << "\033[90m|\033[1;36m"; // Border color then back to cyan
} else {
std::cout << "\033[90m"; // Just border color for last column
std::cout << "\033[90m|"; // Just border color for last column
}
}
std::cout << std::endl;
// Print header separator
if (!mCompact) {
std::cout << "";
std::cout << "+";
for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) {
std::cout << "-";
}
if (i < rows[0].size() - 1) std::cout << "";
if (i < rows[0].size() - 1) std::cout << "+";
}
std::cout << "" << std::endl;
std::cout << "+" << std::endl;
}
// Print rows
for (size_t row_idx = 1; row_idx < rows.size(); ++row_idx) {
const auto& row = rows[row_idx];
std::cout << "";
std::cout << "|";
for (size_t i = 0; i < row.size(); ++i) {
// Set the appropriate color for the row
std::string rowcolor = (row_idx % 2 == 1) ? "\033[38;5;142m" : "\033[38;5;250m";
std::cout << width_print_left(row[i],col_widths[i]+2,rowcolor);
std::cout << "\033[90m" << "";
std::cout << "\033[90m" << "|";
}
std::cout << std::endl;
// Print row separator if not the last row
if (row_idx < rows.size() - 1 && !mCompact) {
std::cout << "";
std::cout << "+";
for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) {
std::cout << "-";
}
if (i < rows[0].size() - 1) std::cout << "";
if (i < rows[0].size() - 1) std::cout << "+";
}
std::cout << "" << std::endl;
std::cout << "+" << std::endl;
}
}
// Print bottom border
std::cout << "";
std::cout << "+";
for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) {
std::cout << "-";
}
if (i < rows[0].size() - 1) std::cout << "";
if (i < rows[0].size() - 1) std::cout << "+";
}
std::cout << "" << "\033[0m" << std::endl; // Reset color
std::cout << "+" << "\033[0m" << std::endl; // Reset color
}