Adapt screen to resized window
This commit is contained in:
@@ -4,8 +4,11 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <argparse/argparse.hpp>
|
#include <argparse/argparse.hpp>
|
||||||
#include "manage/ManageScreen.h"
|
#include "manage/ManageScreen.h"
|
||||||
|
#include <signal.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
platform::ManageScreen* manager = nullptr;
|
||||||
|
|
||||||
void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
|
void manageArguments(argparse::ArgumentParser& program, int argc, char** argv)
|
||||||
{
|
{
|
||||||
program.add_argument("-m", "--model").default_value("any").help("Filter results of the selected model)");
|
program.add_argument("-m", "--model").default_value("any").help("Filter results of the selected model)");
|
||||||
@@ -42,6 +45,11 @@ std::pair<int, int> numRowsCols()
|
|||||||
return { ts.ws_row, ts.ws_col };
|
return { ts.ws_row, ts.ws_col };
|
||||||
#endif /* TIOCGSIZE */
|
#endif /* TIOCGSIZE */
|
||||||
}
|
}
|
||||||
|
void handleResize(int sig)
|
||||||
|
{
|
||||||
|
auto [rows, cols] = numRowsCols();
|
||||||
|
manager->updateSize(rows, cols);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@@ -50,13 +58,15 @@ int main(int argc, char** argv)
|
|||||||
std::string model = program.get<std::string>("model");
|
std::string model = program.get<std::string>("model");
|
||||||
std::string score = program.get<std::string>("score");
|
std::string score = program.get<std::string>("score");
|
||||||
std::string platform = program.get<std::string>("platform");
|
std::string platform = program.get<std::string>("platform");
|
||||||
auto complete = program.get<bool>("complete");
|
bool complete = program.get<bool>("complete");
|
||||||
auto partial = program.get<bool>("partial");
|
bool partial = program.get<bool>("partial");
|
||||||
auto compare = program.get<bool>("compare");
|
bool compare = program.get<bool>("compare");
|
||||||
auto [rows, cols] = numRowsCols();
|
|
||||||
if (complete)
|
if (complete)
|
||||||
partial = false;
|
partial = false;
|
||||||
auto manager = platform::ManageScreen(rows, cols, model, score, platform, complete, partial, compare);
|
signal(SIGWINCH, handleResize);
|
||||||
manager.doMenu();
|
auto [rows, cols] = numRowsCols();
|
||||||
|
manager = new platform::ManageScreen(rows, cols, model, score, platform, complete, partial, compare);
|
||||||
|
manager->doMenu();
|
||||||
|
delete manager;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -24,21 +24,16 @@ namespace platform {
|
|||||||
results.load();
|
results.load();
|
||||||
openExcel = false;
|
openExcel = false;
|
||||||
workbook = NULL;
|
workbook = NULL;
|
||||||
this->rows = std::max(0, rows - 6); // 6 is the number of lines used by the menu & header
|
this->rows = std::max(6, rows - 6); // 6 is the number of lines used by the menu & header
|
||||||
maxModel = results.maxModelSize();
|
maxModel = results.maxModelSize();
|
||||||
maxTitle = results.maxTitleSize();
|
maxTitle = results.maxTitleSize();
|
||||||
header_lengths = { 3, 10, maxModel, 11, 10, 12, 2, 3, 7, maxTitle };
|
header_lengths = { 3, 10, maxModel, 11, 10, 12, 2, 3, 7, maxTitle };
|
||||||
header_labels = { " #", "Date", "Model", "Score Name", "Score", "Platform", "SD", "C/P", "Time", "Title" };
|
header_labels = { " #", "Date", "Model", "Score Name", "Score", "Platform", "SD", "C/P", "Time", "Title" };
|
||||||
sort_fields = { "Date", "Model", "Score", "Time" };
|
sort_fields = { "Date", "Model", "Score", "Time" };
|
||||||
int minTitle = 10;
|
computeSizes();
|
||||||
// set 10 chars as minimum for Title
|
if (min_columns > cols) {
|
||||||
int columns = std::accumulate(header_lengths.begin(), header_lengths.end(), 0) + header_lengths.size() - maxTitle + minTitle;
|
throw std::runtime_error("Make screen bigger to fit the results! " + std::to_string(min_columns - cols) + " columns needed! ");
|
||||||
if (columns > cols) {
|
|
||||||
throw std::runtime_error("Make screen bigger to fit the results! " + std::to_string(columns - cols) + " columns needed! ");
|
|
||||||
}
|
}
|
||||||
maxTitle = minTitle + cols - columns;
|
|
||||||
header_lengths[header_lengths.size() - 1] = maxTitle;
|
|
||||||
cols = std::min(cols, columns + maxTitle);
|
|
||||||
// Initializes the paginator for each output type (experiments, datasets, result)
|
// Initializes the paginator for each output type (experiments, datasets, result)
|
||||||
for (int i = 0; i < static_cast<int>(OutputType::Count); i++) {
|
for (int i = 0; i < static_cast<int>(OutputType::Count); i++) {
|
||||||
paginator.push_back(Paginator(this->rows, results.size()));
|
paginator.push_back(Paginator(this->rows, results.size()));
|
||||||
@@ -49,6 +44,27 @@ namespace platform {
|
|||||||
subIndex = -1;
|
subIndex = -1;
|
||||||
output_type = OutputType::EXPERIMENTS;
|
output_type = OutputType::EXPERIMENTS;
|
||||||
}
|
}
|
||||||
|
void ManageScreen::computeSizes()
|
||||||
|
{
|
||||||
|
int minTitle = 10;
|
||||||
|
// set 10 chars as minimum for Title
|
||||||
|
auto header_title = header_lengths[header_lengths.size() - 1];
|
||||||
|
min_columns = std::accumulate(header_lengths.begin(), header_lengths.end(), 0) + header_lengths.size() - header_title + minTitle;
|
||||||
|
maxTitle = minTitle + cols - min_columns;
|
||||||
|
header_lengths[header_lengths.size() - 1] = maxTitle;
|
||||||
|
cols = std::min(cols, min_columns + maxTitle);
|
||||||
|
for (auto& paginator_ : paginator) {
|
||||||
|
paginator_.setPageSize(rows);
|
||||||
|
}
|
||||||
|
resize = false;
|
||||||
|
}
|
||||||
|
void ManageScreen::updateSize(int rows_, int cols_)
|
||||||
|
{
|
||||||
|
rows = std::max(6, rows_ - 6); // 6 is the number of lines used by the menu & header
|
||||||
|
cols = cols_;
|
||||||
|
resize = true;
|
||||||
|
computeSizes();
|
||||||
|
}
|
||||||
void ManageScreen::doMenu()
|
void ManageScreen::doMenu()
|
||||||
{
|
{
|
||||||
if (results.empty()) {
|
if (results.empty()) {
|
||||||
@@ -212,7 +228,6 @@ namespace platform {
|
|||||||
std::cout << Colors::RESET();
|
std::cout << Colors::RESET();
|
||||||
std::string arrow_dn = Symbols::down_arrow + " ";
|
std::string arrow_dn = Symbols::down_arrow + " ";
|
||||||
std::string arrow_up = Symbols::up_arrow + " ";
|
std::string arrow_up = Symbols::up_arrow + " ";
|
||||||
|
|
||||||
for (int i = 0; i < header_labels.size(); i++) {
|
for (int i = 0; i < header_labels.size(); i++) {
|
||||||
std::string suffix = "", color = Colors::GREEN();
|
std::string suffix = "", color = Colors::GREEN();
|
||||||
int diff = 0;
|
int diff = 0;
|
||||||
@@ -358,14 +373,19 @@ namespace platform {
|
|||||||
{"Page+", '+', false},
|
{"Page+", '+', false},
|
||||||
{"Page-", '-', false}
|
{"Page-", '-', false}
|
||||||
};
|
};
|
||||||
auto main_menu = OptionsMenu(mainOptions, Colors::IGREEN(), Colors::YELLOW(), cols);
|
|
||||||
auto list_menu = OptionsMenu(listOptions, Colors::IBLUE(), Colors::YELLOW(), cols);
|
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
|
auto main_menu = OptionsMenu(mainOptions, Colors::IGREEN(), Colors::YELLOW(), cols);
|
||||||
|
auto list_menu = OptionsMenu(listOptions, Colors::IBLUE(), Colors::YELLOW(), cols);
|
||||||
OptionsMenu& menu = output_type == OutputType::EXPERIMENTS ? main_menu : list_menu;
|
OptionsMenu& menu = output_type == OutputType::EXPERIMENTS ? main_menu : list_menu;
|
||||||
bool parserError = true; // force the first iteration
|
bool parserError = true; // force the first iteration
|
||||||
while (parserError) {
|
while (parserError) {
|
||||||
|
if (min_columns > cols) {
|
||||||
|
throw std::runtime_error("Make screen bigger to fit the results! " + std::to_string(min_columns - cols) + " columns needed! ");
|
||||||
|
}
|
||||||
auto [min_index, max_index] = paginator[static_cast<int>(output_type)].getOffset();
|
auto [min_index, max_index] = paginator[static_cast<int>(output_type)].getOffset();
|
||||||
std::tie(option, index, parserError) = menu.parse('r', min_index, max_index);
|
std::tie(option, index, parserError) = menu.parse('r', min_index, max_index);
|
||||||
|
menu.updateColumns(cols);
|
||||||
if (parserError) {
|
if (parserError) {
|
||||||
list(menu.getErrorMessage(), Colors::RED());
|
list(menu.getErrorMessage(), Colors::RED());
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ namespace platform {
|
|||||||
ManageScreen(int rows, int cols, const std::string& model, const std::string& score, const std::string& platform, bool complete, bool partial, bool compare);
|
ManageScreen(int rows, int cols, const std::string& model, const std::string& score, const std::string& platform, bool complete, bool partial, bool compare);
|
||||||
~ManageScreen() = default;
|
~ManageScreen() = default;
|
||||||
void doMenu();
|
void doMenu();
|
||||||
|
void updateSize(int rows, int cols);
|
||||||
private:
|
private:
|
||||||
void list(const std::string& status, const std::string& color);
|
void list(const std::string& status, const std::string& color);
|
||||||
void list_experiments(const std::string& status, const std::string& color);
|
void list_experiments(const std::string& status, const std::string& color);
|
||||||
@@ -29,12 +30,14 @@ namespace platform {
|
|||||||
std::string report_compared();
|
std::string report_compared();
|
||||||
std::pair<std::string, std::string> sortList();
|
std::pair<std::string, std::string> sortList();
|
||||||
std::string getVersions();
|
std::string getVersions();
|
||||||
|
void computeSizes();
|
||||||
void menu();
|
void menu();
|
||||||
void header();
|
void header();
|
||||||
void footer(const std::string& status, const std::string& color);
|
void footer(const std::string& status, const std::string& color);
|
||||||
OutputType output_type;
|
OutputType output_type;
|
||||||
int rows;
|
int rows;
|
||||||
int cols;
|
int cols;
|
||||||
|
int min_columns;
|
||||||
int index;
|
int index;
|
||||||
int subIndex;
|
int subIndex;
|
||||||
int index_A, index_B; // used for comparison of experiments
|
int index_A, index_B; // used for comparison of experiments
|
||||||
@@ -44,6 +47,7 @@ namespace platform {
|
|||||||
bool complete;
|
bool complete;
|
||||||
bool partial;
|
bool partial;
|
||||||
bool compare;
|
bool compare;
|
||||||
|
bool resize = false;
|
||||||
int maxModel, maxTitle;
|
int maxModel, maxTitle;
|
||||||
std::vector<std::string> header_labels;
|
std::vector<std::string> header_labels;
|
||||||
std::vector<int> header_lengths;
|
std::vector<int> header_lengths;
|
||||||
|
@@ -8,8 +8,8 @@ namespace platform {
|
|||||||
std::string OptionsMenu::to_string()
|
std::string OptionsMenu::to_string()
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
size_t size = 0;
|
|
||||||
std::string result = color_normal + "Options: (";
|
std::string result = color_normal + "Options: (";
|
||||||
|
size_t size = 10; // Size of "Options: ("
|
||||||
for (auto& option : options) {
|
for (auto& option : options) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
result += ", ";
|
result += ", ";
|
||||||
|
@@ -13,6 +13,7 @@ namespace platform {
|
|||||||
char getCommand() const { return command; };
|
char getCommand() const { return command; };
|
||||||
int getIndex() const { return index; };
|
int getIndex() const { return index; };
|
||||||
std::string getErrorMessage() const { return errorMessage; };
|
std::string getErrorMessage() const { return errorMessage; };
|
||||||
|
void updateColumns(int cols) { this->cols = cols; }
|
||||||
private:
|
private:
|
||||||
std::vector<std::tuple<std::string, char, bool>>& options;
|
std::vector<std::tuple<std::string, char, bool>>& options;
|
||||||
std::string color_normal, color_bold;
|
std::string color_normal, color_bold;
|
||||||
|
@@ -54,4 +54,6 @@ private:
|
|||||||
int page;
|
int page;
|
||||||
int numPages;
|
int numPages;
|
||||||
};
|
};
|
||||||
|
//Options: (quit, list, Delete, datasets, hide, sort, report, excel, title, set A, set B, compare A~B, page, Page+, Page-
|
||||||
|
//123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456798012345678901234567890(120)
|
||||||
#endif
|
#endif
|
Reference in New Issue
Block a user