cli: Ajoute de la couleur aux infos du paquet
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -13,4 +14,8 @@ namespace oki{
|
||||
}
|
||||
return xdgData / fs::path{"oki"};
|
||||
}
|
||||
|
||||
bool acceptColor() {
|
||||
return isatty(fileno(stdout));
|
||||
}
|
||||
}
|
||||
|
@@ -4,4 +4,5 @@
|
||||
|
||||
namespace oki{
|
||||
std::filesystem::path getDefaultLocalRepository();
|
||||
bool acceptColor();
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "cli/options.h"
|
||||
#include "config/config.h"
|
||||
#include "repository/RemoteRepository.h"
|
||||
|
||||
using namespace oki;
|
||||
@@ -16,6 +17,7 @@ std::size_t writeCallback(char *in, size_t size, size_t nmemb, std::string *out)
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
bool color = acceptColor();
|
||||
CliAction action = parseArguments(argc, argv);
|
||||
RemoteRepository repository{"http://localhost:8000"};
|
||||
if (std::holds_alternative<ListAction>(action)) {
|
||||
@@ -28,9 +30,15 @@ int main(int argc, char *argv[]) {
|
||||
std::optional<Package> p = repository.showPackage(show->packageName);
|
||||
if(p == std::nullopt){
|
||||
std::cout << "Le package n'existe pas\n";
|
||||
} else {
|
||||
if (color) {
|
||||
std::cout << "\e[32m" << p->getShortName() << "\e[0m/";
|
||||
} else {
|
||||
std::cout << p->getShortName() << "/";
|
||||
}
|
||||
const Version& latest = p->getVersions().front();
|
||||
std::cout << latest.getIdentifier() << latest.getPublishedDate()<< "\n\t" << p->getLongName() << "\n";
|
||||
}
|
||||
else std::cout << p->getShortName() << "/" << p->getVersions().front().getIdentifier() << "\t"
|
||||
<< p->getVersions().front().getPublishedDate()<< "\n\t" << p->getLongName() << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user