Skip to content

Commit

Permalink
added version number column width scaling to Name | Latest Ver. | Ins…
Browse files Browse the repository at this point in the history
…talled? | Description

--------------------|-------------|-------------|--------------
Chumpinate          | N/A         | yes         | Two classes (Package & PackageVersion) to help create packages to be used with ChuMP (the ChucK Mana...
Patch               | N/A         | yes         | Pipe UGen signals into UGen methods directly! The primary use of this is easily and efficiently cont...
Line                | 1.0.0       | yes         | Envelope of a arbitrary ramps (ala Max/PD's line~ object)
  • Loading branch information
nshaheed committed Jan 16, 2025
1 parent b3d2023 commit 65195d1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
39 changes: 28 additions & 11 deletions include/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <thread>
#include <tuple>
#include <vector>
#include <filesystem>

#include "manager.h"
#include "util.h"
Expand All @@ -20,6 +21,8 @@

using std::endl;

namespace fs = std::filesystem;

std::string printLogo();
void printPackage(Package pkg);
void printPackages(Manager *mgr);
Expand Down Expand Up @@ -89,24 +92,38 @@ void printInstalledPackages(Manager *mgr) {

// get maximum package path length
int max_path_len = string("Install Path").length();
int max_ver_len = string("Ver.").length();

// get the character width of the longest install path and version string
for (Package p : packages) {
// skip if not installed
if (!mgr->is_installed(p))
continue;

int curr_path_len = mgr->install_path(p).string().length();
fs::path install_path = mgr->install_path(p);
int curr_path_len = install_path.string().length();

max_path_len = std::max(max_path_len, curr_path_len);

optional<InstalledVersion> installed_version =
mgr->open_installed_version_file(install_path / "version.json");

if (installed_version) {
string version = installed_version.value().getVersionString();
int curr_ver_len = version.length();

max_ver_len = std::max(max_ver_len, curr_ver_len);
}
}

std::cout << std::left << std::setw(20) << "Name"
<< "| " << std::setw(12) << "Latest Ver."
<< "| " << std::setw(max_ver_len) << "Ver."
<< "| " << std::setw(max_path_len + 1) << "Install Path"
<< "| " << std::setw(12) << "Description" << std::endl;

std::cout << std::setfill('-'); // in-between line from header to table

std::cout << std::right << std::setw(21) << "|" << std::setw(14) << "|"
std::cout << std::right << std::setw(21) << "|" << std::setw(max_ver_len + 3) << "|"
<< std::setw(max_path_len + 3) << "|" << std::setw(14) << ""
<< std::endl;

Expand All @@ -116,18 +133,18 @@ void printInstalledPackages(Manager *mgr) {
if (!mgr->is_installed(p))
continue;

optional<PackageVersion> latest = mgr->latestPackageVersion(p.name);
string install_path = mgr->install_path(p).string();
fs::path install_path = mgr->install_path(p);

string latest_version = "N/A";
if (latest)
latest_version = latest.value().getVersionString();
optional<InstalledVersion> installed_version =
mgr->open_installed_version_file(install_path / "version.json");

// string installed = mgr->is_installed(p) ? "yes" : "no";
string version = "N/A";
if (installed_version)
version = installed_version.value().getVersionString();

std::cout << std::left << std::setw(20) << truncate(p.name, 17, true)
<< "| " << std::setw(12) << latest_version << "| "
<< std::setw(max_path_len + 1) << install_path << "| "
<< "| " << std::setw(max_ver_len + 1) << version << "| "
<< std::setw(max_path_len + 1) << install_path.string() << "| "
<< std::setw(12) << truncate(p.description, 100, true)
<< std::endl;
}
Expand Down
2 changes: 2 additions & 0 deletions include/package.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ struct InstalledVersion {
string os;
Architecture arch;
vector<fs::path> files;

string getVersionString() const;
};

// Function declarations for JSON serialization/deserialization
Expand Down
7 changes: 7 additions & 0 deletions src/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,13 @@ Package InstalledVersion::package() {
return pkg;
}

string InstalledVersion::getVersionString() const {
std::ostringstream stringStream;
stringStream << major << "." << minor << "." << patch;

return stringStream.str();
}

void to_json(json &j, const InstalledVersion &p) {
j = json{
{"name", p.name},
Expand Down

0 comments on commit 65195d1

Please sign in to comment.