tableprint!

This commit is contained in:
Your Name
2025-04-21 20:47:03 +12:00
parent 03b02b9094
commit b954338cf5
3 changed files with 80 additions and 25 deletions

View File

@ -2,6 +2,7 @@
#include "dropshell.hpp"
#include "server_env.hpp"
#include "server_service.hpp"
#include "tableprint.hpp"
#include <iostream>
#include <fstream>
#include <iomanip>
@ -52,34 +53,13 @@ std::vector<ServerInfo> get_configured_servers() {
void list_servers() {
auto servers = get_configured_servers();
if (servers.empty()) {
std::cout << "No servers configured." << std::endl;
return;
}
// Find maximum lengths for formatting
size_t max_name_len = 4; // "Name" is 4 chars
size_t max_addr_len = 7; // "Address" is 7 chars
tableprint tp;
tp.add_row({"Name", "Address"});
for (const auto& server : servers) {
max_name_len = std::max(max_name_len, server.name.length());
max_addr_len = std::max(max_addr_len, server.ssh_host.length());
}
// Print header
std::cout << std::left << std::setw(max_name_len) << "Name" << " | "
<< std::setw(max_addr_len) << "Address" << std::endl;
// Print separator
std::cout << std::string(max_name_len, '-') << "-+-"
<< std::string(max_addr_len, '-') << std::endl;
// Print server rows
for (const auto& server : servers) {
std::cout << std::left << std::setw(max_name_len) << server.name << " | "
<< std::setw(max_addr_len) << server.ssh_host << std::endl;
tp.add_row({server.name, server.ssh_host});
}
tp.print();
}
void show_server_details(const std::string& server_name) {