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

@@ -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);