info for table print
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name 2025-05-18 14:03:12 +12:00
parent 6c99b429b9
commit b278e81533

View File

@ -9,6 +9,8 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include "output.hpp"
enum kTextColors { enum kTextColors {
kTextColor_Default, kTextColor_Default,
kTextColor_Red, kTextColor_Red,
@ -32,7 +34,7 @@ const std::map<std::string, coloredText> kReplacements = {
{":tick:", {"+", kTextColor_Green}}, {":tick:", {"+", kTextColor_Green}},
{":cross:", {"x", kTextColor_Red}}, {":cross:", {"x", kTextColor_Red}},
{":warning:", {"!", kTextColor_Yellow}}, {":warning:", {"!", kTextColor_Yellow}},
{":info:", {"i", kTextColor_Blue}}, {":dropshell::info:", {"i", kTextColor_Blue}},
{":check:", {"+", kTextColor_Green}}, {":check:", {"+", kTextColor_Green}},
{":x:", {"x", kTextColor_Red}}, {":x:", {"x", kTextColor_Red}},
{":error:", {"!", kTextColor_Red}}, {":error:", {"!", kTextColor_Red}},
@ -115,12 +117,12 @@ std::string width_print_centered(std::string str,int width, std::string rowcolor
oss << rowcolor << std::string(lpad, ' ') << process_cell(str, rowcolor) << oss << rowcolor << std::string(lpad, ' ') << process_cell(str, rowcolor) <<
std::string(rpad, ' ') << "\033[0m"; std::string(rpad, ' ') << "\033[0m";
// std::cout << "str = "<<str <<std::endl; // dropshell::info << "str = "<<str <<std::endl;
// std::cout << "width = "<<width <<std::endl; // dropshell::info << "width = "<<width <<std::endl;
// std::cout << "padding = "<<padding <<std::endl; // dropshell::info << "padding = "<<padding <<std::endl;
// std::cout << "get_visible_length(str) = "<<get_visible_length(str) <<std::endl; // dropshell::info << "get_visible_length(str) = "<<get_visible_length(str) <<std::endl;
// std::cout << "get_codepoints(str) = "<<get_codepoints(str) <<std::endl; // dropshell::info << "get_codepoints(str) = "<<get_codepoints(str) <<std::endl;
// std::cout << "oss.str() = ["<<oss.str() <<"]"<<std::endl; // dropshell::info << "oss.str() = ["<<oss.str() <<"]"<<std::endl;
return oss.str(); return oss.str();
} }
@ -195,98 +197,105 @@ void tableprint::print() {
// Print title if it exists // Print title if it exists
if (!title.empty()) { if (!title.empty()) {
std::cout << "\033[90m"; // Dark grey color for borders dropshell::info << "\033[90m"; // Dark grey color for borders
std::cout << "+"; dropshell::info << "+";
for (size_t i = 0; i < rows[0].size(); ++i) { for (size_t i = 0; i < rows[0].size(); ++i) {
std::cout << std::string(col_widths[i] + 2, '-'); dropshell::info << std::string(col_widths[i] + 2, '-');
if (i < rows[0].size() - 1) std::cout << "-"; if (i < rows[0].size() - 1) dropshell::info << "-";
} }
std::cout << "+" << std::endl; dropshell::info << "+" << std::endl;
std::cout << "|"; // White color for title dropshell::info << "\033[90m"; // Dark grey color for borders
dropshell::info << "|"; // White color for title
size_t title_width = 0; size_t title_width = 0;
for (size_t width : col_widths) { for (size_t width : col_widths) {
title_width += width + 2; // +2 for padding title_width += width + 2; // +2 for padding
} }
title_width += col_widths.size() - 1; // Add space for vertical borders title_width += col_widths.size() - 1; // Add space for vertical borders
std::cout << width_print_centered(title,title_width,"\033[1;37m"); dropshell::info << width_print_centered(title,title_width,"\033[1;37m");
std::cout << "\033[90m|" << std::endl; dropshell::info << "\033[90m|" << std::endl;
// Use └─┴─┘ for bottom of title box to connect with table // Use └─┴─┘ for bottom of title box to connect with table
std::cout << "+"; dropshell::info << "\033[90m"; // Dark grey color for borders
dropshell::info << "+";
for (size_t i = 0; i < rows[0].size(); ++i) { for (size_t i = 0; i < rows[0].size(); ++i) {
std::cout << std::string(col_widths[i] + 2, '-'); dropshell::info << std::string(col_widths[i] + 2, '-');
if (i < rows[0].size() - 1) std::cout << "-"; if (i < rows[0].size() - 1) dropshell::info << "-";
} }
std::cout << "+" << std::endl; dropshell::info << "+" << std::endl;
} else { } else {
// Print top border if no title // Print top border if no title
std::cout << "\033[90m"; // Dark grey color for borders dropshell::info << "\033[90m"; // Dark grey color for borders
std::cout << "+"; dropshell::info << "+";
for (size_t i = 0; i < rows[0].size(); ++i) { for (size_t i = 0; i < rows[0].size(); ++i) {
std::cout << std::string(col_widths[i] + 2, '-'); dropshell::info << std::string(col_widths[i] + 2, '-');
if (i < rows[0].size() - 1) std::cout << "+"; if (i < rows[0].size() - 1) dropshell::info << "+";
} }
std::cout << "+" << std::endl; dropshell::info << "+" << std::endl;
} }
// Print header // Print header
std::cout << "|"; dropshell::info << "\033[90m"; // Dark grey color for borders
dropshell::info << "|";
for (size_t i = 0; i < rows[0].size(); ++i) { 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"); dropshell::info << width_print_centered(rows[0][i],col_widths[i]+2,"\033[1;36m");
if (i < rows[0].size() - 1) { if (i < rows[0].size() - 1) {
std::cout << "\033[90m|\033[1;36m"; // Border color then back to cyan dropshell::info << "\033[90m|\033[1;36m"; // Border color then back to cyan
} else { } else {
std::cout << "\033[90m|"; // Just border color for last column dropshell::info << "\033[90m|"; // Just border color for last column
} }
} }
std::cout << std::endl; dropshell::info << std::endl;
// Print header separator // Print header separator
if (!mCompact) { if (!mCompact) {
std::cout << "+"; dropshell::info << "\033[90m"; // Dark grey color for borders
dropshell::info << "+";
for (size_t i = 0; i < rows[0].size(); ++i) { for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) { for (size_t j = 0; j < col_widths[i] + 2; ++j) {
std::cout << "-"; dropshell::info << "-";
} }
if (i < rows[0].size() - 1) std::cout << "+"; if (i < rows[0].size() - 1) dropshell::info << "+";
} }
std::cout << "+" << std::endl; dropshell::info << "+" << std::endl;
} }
// Print rows // Print rows
for (size_t row_idx = 1; row_idx < rows.size(); ++row_idx) { for (size_t row_idx = 1; row_idx < rows.size(); ++row_idx) {
const auto& row = rows[row_idx]; const auto& row = rows[row_idx];
std::cout << "|"; dropshell::info << "\033[90m"; // Dark grey color for borders
dropshell::info << "|";
for (size_t i = 0; i < row.size(); ++i) { for (size_t i = 0; i < row.size(); ++i) {
// Set the appropriate color for the row // Set the appropriate color for the row
std::string rowcolor = (row_idx % 2 == 1) ? "\033[38;5;142m" : "\033[38;5;250m"; 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); dropshell::info << width_print_left(row[i],col_widths[i]+2,rowcolor);
std::cout << "\033[90m" << "|"; dropshell::info << "\033[90m" << "|";
} }
std::cout << std::endl; dropshell::info << std::endl;
// Print row separator if not the last row // Print row separator if not the last row
if (row_idx < rows.size() - 1 && !mCompact) { if (row_idx < rows.size() - 1 && !mCompact) {
std::cout << "+"; dropshell::info << "\033[90m"; // Dark grey color for borders
dropshell::info << "+";
for (size_t i = 0; i < rows[0].size(); ++i) { for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) { for (size_t j = 0; j < col_widths[i] + 2; ++j) {
std::cout << "-"; dropshell::info << "-";
} }
if (i < rows[0].size() - 1) std::cout << "+"; if (i < rows[0].size() - 1) dropshell::info << "+";
} }
std::cout << "+" << std::endl; dropshell::info << "+" << std::endl;
} }
} }
// Print bottom border // Print bottom border
std::cout << "+"; dropshell::info << "\033[90m"; // Dark grey color for borders
dropshell::info << "+";
for (size_t i = 0; i < rows[0].size(); ++i) { for (size_t i = 0; i < rows[0].size(); ++i) {
for (size_t j = 0; j < col_widths[i] + 2; ++j) { for (size_t j = 0; j < col_widths[i] + 2; ++j) {
std::cout << "-"; dropshell::info << "-";
} }
if (i < rows[0].size() - 1) std::cout << "+"; if (i < rows[0].size() - 1) dropshell::info << "+";
} }
std::cout << "+" << "\033[0m" << std::endl; // Reset color dropshell::info << "+" << "\033[0m" << std::endl; // Reset color
} }