Title
This commit is contained in:
parent
b135bed29c
commit
749efef29d
@ -54,7 +54,7 @@ std::vector<ServerInfo> get_configured_servers() {
|
||||
void list_servers() {
|
||||
auto servers = get_configured_servers();
|
||||
|
||||
tableprint tp;
|
||||
tableprint tp("All DropShell Servers");
|
||||
tp.add_row({"Name", "Address"});
|
||||
for (const auto& server : servers) {
|
||||
tp.add_row({server.name, server.ssh_host});
|
||||
|
@ -4,13 +4,17 @@
|
||||
#include <locale>
|
||||
#include <cwchar>
|
||||
|
||||
tableprint::tableprint() {
|
||||
tableprint::tableprint(const std::string title) : title(title) {
|
||||
// Set locale for wide character support
|
||||
std::setlocale(LC_ALL, "");
|
||||
}
|
||||
|
||||
tableprint::~tableprint() {}
|
||||
|
||||
void tableprint::set_title(const std::string title) {
|
||||
this->title = title;
|
||||
}
|
||||
|
||||
void tableprint::add_row(const std::vector<std::string>& row) {
|
||||
rows.push_back(row);
|
||||
}
|
||||
@ -26,6 +30,25 @@ void tableprint::print() {
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate total table width
|
||||
size_t total_width = 0;
|
||||
for (size_t width : col_widths) {
|
||||
total_width += width + 2; // +2 for padding
|
||||
}
|
||||
total_width += col_widths.size() - 1; // Add space for vertical borders
|
||||
|
||||
// Print title if it exists
|
||||
if (!title.empty()) {
|
||||
std::wcout << L"\033[90m"; // Dark grey color for borders
|
||||
std::wcout << L"┌" << std::wstring(total_width, L'─') << L"┐" << std::endl;
|
||||
std::wcout << L"│" << L"\033[1;37m"; // White color for title
|
||||
size_t padding = (total_width - title.length()) / 2;
|
||||
std::wcout << std::wstring(padding, L' ') << std::wstring(title.begin(), title.end())
|
||||
<< std::wstring(total_width - title.length() - padding, L' ');
|
||||
std::wcout << L"\033[90m│" << std::endl;
|
||||
std::wcout << L"└" << std::wstring(total_width, L'─') << L"┘" << std::endl;
|
||||
}
|
||||
|
||||
// Print top border
|
||||
std::wcout << L"\033[90m"; // Dark grey color for borders
|
||||
std::wcout << L"┌";
|
||||
|
@ -11,12 +11,14 @@
|
||||
// assumes the first row is the header.
|
||||
class tableprint {
|
||||
public:
|
||||
tableprint();
|
||||
tableprint(const std::string title = "");
|
||||
~tableprint();
|
||||
void add_row(const std::vector<std::string>& row);
|
||||
void print();
|
||||
void set_title(const std::string title);
|
||||
private:
|
||||
std::vector<std::vector<std::string>> rows;
|
||||
std::string title;
|
||||
};
|
||||
|
||||
# endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user