This commit is contained in:
@ -173,7 +173,7 @@ namespace localpath {
|
||||
|
||||
std::string remotepath::DROPSHELL_DIR() const
|
||||
{
|
||||
return server_config(mServer_name).get_user_dir(mUser);
|
||||
return ServerConfig(mServer_name).get_user_dir(mUser);
|
||||
}
|
||||
|
||||
std::string remotepath::services() const
|
||||
|
@ -147,6 +147,27 @@ void tableprint::set_title(const std::string title) {
|
||||
this->title = title;
|
||||
}
|
||||
|
||||
// gives the columns to sort by, starting at 0.
|
||||
void tableprint::sort(std::vector<int> sort_columns)
|
||||
{
|
||||
// Skip header row and sort remaining rows
|
||||
if (rows.size() <= 1) return; // Only header or empty table
|
||||
|
||||
// Create a custom comparator that compares rows based on the specified columns
|
||||
auto comparator = [this, &sort_columns](const std::vector<std::string>& a, const std::vector<std::string>& b) {
|
||||
for (int col : sort_columns) {
|
||||
if (col >= 0 && col < a.size() && col < b.size()) {
|
||||
int cmp = a[col].compare(b[col]);
|
||||
if (cmp != 0) return cmp < 0;
|
||||
}
|
||||
}
|
||||
return false; // Equal rows maintain original order
|
||||
};
|
||||
|
||||
// Sort rows starting from index 1 (after header)
|
||||
std::sort(rows.begin() + 1, rows.end(), comparator);
|
||||
}
|
||||
|
||||
void tableprint::add_row(const std::vector<std::string>& row) {
|
||||
std::vector<std::string> trimmed_row;
|
||||
for (const auto& cell : row) {
|
||||
|
@ -16,6 +16,7 @@ class tableprint {
|
||||
void add_row(const std::vector<std::string>& row);
|
||||
void print();
|
||||
void set_title(const std::string title);
|
||||
void sort(std::vector<int> sort_columns);
|
||||
private:
|
||||
std::vector<std::vector<std::string>> rows;
|
||||
std::string title;
|
||||
|
Reference in New Issue
Block a user