From 013176dbe5b955887ddcebbac7e25d273cc24418 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 21 Apr 2025 22:39:09 +1200 Subject: [PATCH] Fixed. --- src/tableprint.cpp | 53 +++++++--------------------------------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/src/tableprint.cpp b/src/tableprint.cpp index e71a20c..f9eaa35 100644 --- a/src/tableprint.cpp +++ b/src/tableprint.cpp @@ -104,23 +104,25 @@ std::string process_cell(std::string str,std::string rowcolor) { } std::string width_print_centered(std::string str,int width, std::string rowcolor) { - size_t padding = (width - get_visible_length(str)) / 2; + size_t padding = (width - get_visible_length(str)); + size_t lpad = padding/2; + size_t rpad = padding - lpad; std::ostringstream oss; - oss << rowcolor << std::string(padding, ' ') << process_cell(str, rowcolor) << - std::string(width - get_codepoints(str) - padding, ' ') << "\033[0m"; + oss << rowcolor << std::string(lpad, ' ') << process_cell(str, rowcolor) << + std::string(rpad, ' ') << "\033[0m"; // std::cout << "str = "<1 ? 1 : 0); size_t rpad = padding - lpad; std::ostringstream oss; @@ -128,45 +130,6 @@ std::string width_print_left(std::string str,int width, std::string rowcolor) { return oss.str(); } - -// // Helper function to process a cell with replacements -// std::string process_cell(const std::string& cell) { -// std::string result; -// size_t pos = 0; -// while (pos < cell.length()) { -// bool found_replacement = false; -// for (const auto& [key, value] : kReplacements) { -// if (cell.compare(pos, key.length(), key) == 0) { -// result += get_color_code(value.color) + value.text + "\033[0m"; -// pos += key.length(); -// found_replacement = true; -// break; -// } -// } -// if (!found_replacement) { -// result += cell[pos]; -// pos++; -// } -// } -// return result; -// } - -// // Helper function to get visible length (ignoring color codes) -// size_t get_visible_length(const std::string& str) { -// size_t length = 0; -// bool in_color_code = false; -// for (size_t i = 0; i < str.length(); ++i) { -// if (str[i] == '\033') { -// while (i < str.length() && str[i] != 'm') { -// i++; -// } -// } else { -// length++; -// } -// } -// return length; -// } - tableprint::tableprint(const std::string title) : title(title) { // Set locale for wide character support std::setlocale(LC_ALL, ""); @@ -294,7 +257,7 @@ void tableprint::print() { // 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;