Add apply number of lines in terminal in b_manage

This commit is contained in:
2024-03-12 13:23:30 +01:00
parent 0ade72a37a
commit eff0be1c1c
5 changed files with 27 additions and 5 deletions

View File

@@ -10,7 +10,6 @@
#include "ManageResults.h"
namespace platform {
ManageResults::ManageResults(int numFiles, const std::string& model, const std::string& score, bool complete, bool partial, bool compare) :
numFiles{ numFiles }, complete{ complete }, partial{ partial }, compare{ compare }, results(ResultsManager(model, score, complete, partial))
{
@@ -53,8 +52,9 @@ namespace platform {
}
auto i = 0;
int maxModel = results.maxModelSize();
int maxTitle = results.maxTitleSize();
std::cout << Colors::GREEN() << " # Date " << std::setw(maxModel) << std::left << "Model" << " Score Name Score C/P Duration Title" << std::endl;
std::cout << "=== ========== " << std::string(maxModel, '=') << " =========== =========== === ========= =============================================================" << std::endl;
std::cout << "=== ========== " << std::string(maxModel, '=') << " =========== =========== === ========= " << std::string(maxTitle, '=') << std::endl;
bool odd = true;
for (auto& result : results) {
auto color = odd ? Colors::BLUE() : Colors::CYAN();

View File

@@ -4,7 +4,7 @@
namespace platform {
ResultsManager::ResultsManager(const std::string& model, const std::string& score, bool complete, bool partial) :
path(Paths::results()), model(model), scoreName(score), complete(complete), partial(partial), maxModel(0)
path(Paths::results()), model(model), scoreName(score), complete(complete), partial(partial), maxModel(0), maxTitle(0)
{
}
void ResultsManager::load()
@@ -23,6 +23,7 @@ namespace platform {
}
}
maxModel = std::max(size_t(5), (*max_element(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getModel().size() < b.getModel().size(); })).getModel().size());
maxTitle = std::max(size_t(5), (*max_element(files.begin(), files.end(), [](const Result& a, const Result& b) { return a.getTitle().size() < b.getTitle().size(); })).getTitle().size());
}
void ResultsManager::hideResult(int index, const std::string& pathHidden)
{

View File

@@ -15,6 +15,7 @@ namespace platform {
void sortModel();
void sortDuration();
int maxModelSize() const { return maxModel; };
int maxTitleSize() const { return maxTitle; };
void hideResult(int index, const std::string& pathHidden);
void deleteResult(int index);
int size() const;
@@ -29,6 +30,7 @@ namespace platform {
bool complete;
bool partial;
int maxModel;
int maxTitle;
std::vector<Result> files;
};
};

View File

@@ -1,9 +1,10 @@
#include <iostream>
#include <sys/ioctl.h>
#include <unistd.h>
#include <argparse/argparse.hpp>
#include "ManageResults.h"
#include "config.h"
void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
{
program.add_argument("-n", "--number").default_value(0).help("Number of results to show (0 = all)").scan<'i', int>();
@@ -31,6 +32,21 @@ void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
}
}
int numRows()
{
#ifdef TIOCGSIZE
struct ttysize ts;
ioctl(STDIN_FILENO, TIOCGSIZE, &ts);
// cols = ts.ts_cols;
return ts.ts_lines;
#elif defined(TIOCGWINSZ)
struct winsize ts;
ioctl(STDIN_FILENO, TIOCGWINSZ, &ts);
// cols = ts.ws_col;
return ts.ws_row;
#endif /* TIOCGSIZE */
}
int main(int argc, char** argv)
{
auto program = argparse::ArgumentParser("b_manage", { platform_project_version.begin(), platform_project_version.end() });
@@ -41,6 +57,9 @@ int main(int argc, char** argv)
auto complete = program.get<bool>("complete");
auto partial = program.get<bool>("partial");
auto compare = program.get<bool>("compare");
if (number == 0) {
number = std::max(0, numRows() - 5); // 5 is the number of lines used by the menu & header
}
if (complete)
partial = false;
auto manager = platform::ManageResults(number, model, score, complete, partial, compare);