diff --git a/src/servers.cpp b/src/servers.cpp index fdd567e..98fd7cf 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -65,7 +65,7 @@ void list_servers() { if (ss.init(server.name, service)) { if (ss.is_healthy()) - serviceticks += ":tick: :tick: :cross: "; + serviceticks += ":tick: "; else serviceticks += ":cross: "; } @@ -100,15 +100,8 @@ void show_server_details(const std::string& server_name) { return; } - //--------------------- - std::cout << "Server Configuration: " << server_name << std::endl; - std::cout << std::string(40, '-') << std::endl; - server_env env(server_dir.string()); - for (const auto& [key, value] : env.get_variables()) { - std::cout << key << ": " << value << std::endl; - } //--------------------- // Check if server is reachable via SSH @@ -134,39 +127,46 @@ void show_server_details(const std::string& server_name) { } } + //--------------------- + { + tableprint tp("Server Configuration: " + server_name, true); + tp.add_row({"Key", "Value"}); + for (const auto& [key, value] : env.get_variables()) { + tp.add_row({key, value}); + } + tp.print(); + } + //--------------------- // list services, and run healthcheck on each - std::cout << std::endl; - std::cout << "Services: " << server_name << std::endl; - std::cout << std::string(40, '-') << std::endl; - - std::string green_tick = "\033[32m✓\033[0m"; - std::string red_cross = "\033[31m✗\033[0m"; - - std::vector services = get_server_services(server_name); - for (const auto& service : services) { - bool healthy = false; - std::vector ports; - server_service ss; - if (ss.init(server_name, service)) - { - if (ss.is_healthy()) - healthy=true; - ports = ss.get_ports(); - } - std::cout << " " << (healthy ? green_tick : red_cross) << " " << service << ", ports: "; - std::cout << "("; - bool first = true; - for (const auto& port : ports) { - if (!first) { - std::cout << ", "; + { + tableprint tp("Services: " + server_name, false); + tp.add_row({"Status", "Service", "Ports"}); + + std::vector services = get_server_services(server_name); + for (const auto& service : services) { + bool healthy = false; + std::vector ports; + server_service ss; + if (ss.init(server_name, service)) + { + if (ss.is_healthy()) + healthy=true; + ports = ss.get_ports(); } - std::cout << port; - first = false; - } - std::cout << ")" << std::endl; - } - -} + bool first = true; + std::string ports_str = ""; + for (const auto& port : ports) { + if (!first) { + ports_str += ", "; + } + ports_str += std::to_string(port); + first = false; + } + tp.add_row({healthy ? ":tick:" : ":cross:", service, ports_str}); + } // end of for (const auto& service : services) + tp.print(); + } // end of list services +} // end of show_server_details } // namespace dropshell \ No newline at end of file diff --git a/src/tableprint.cpp b/src/tableprint.cpp index f9eaa35..a1550d3 100644 --- a/src/tableprint.cpp +++ b/src/tableprint.cpp @@ -130,7 +130,7 @@ std::string width_print_left(std::string str,int width, std::string rowcolor) { return oss.str(); } -tableprint::tableprint(const std::string title) : title(title) { +tableprint::tableprint(const std::string title, bool compact) : title(title), mCompact(compact) { // Set locale for wide character support std::setlocale(LC_ALL, ""); } @@ -176,11 +176,11 @@ void tableprint::print() { } // Debug output - std::cerr << "Column widths: "; - for (size_t width : col_widths) { - std::cerr << width << " "; - } - std::cerr << std::endl; + // std::cerr << "Column widths: "; + // for (size_t width : col_widths) { + // std::cerr << width << " "; + // } + // std::cerr << std::endl; // Calculate total table width size_t total_width = 0; @@ -240,14 +240,16 @@ void tableprint::print() { std::cout << std::endl; // Print header separator - 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 (!mCompact) { + 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) { @@ -262,7 +264,7 @@ void tableprint::print() { std::cout << std::endl; // Print row separator if not the last row - if (row_idx < rows.size() - 1) { + if (row_idx < rows.size() - 1 && !mCompact) { std::cout << "├"; for (size_t i = 0; i < rows[0].size(); ++i) { for (size_t j = 0; j < col_widths[i] + 2; ++j) { diff --git a/src/tableprint.hpp b/src/tableprint.hpp index 6305887..2fc9ec8 100644 --- a/src/tableprint.hpp +++ b/src/tableprint.hpp @@ -11,7 +11,7 @@ // assumes the first row is the header. class tableprint { public: - tableprint(const std::string title = ""); + tableprint(const std::string title = "", bool compact = false); ~tableprint(); void add_row(const std::vector& row); void print(); @@ -19,6 +19,7 @@ class tableprint { private: std::vector> rows; std::string title; + bool mCompact; }; # endif