Dar formato al código

This commit is contained in:
Somebody Master 2021-05-06 12:00:44 +02:00
parent d12d6ae69b
commit 188eab4896
12 changed files with 397 additions and 351 deletions

View File

@ -4,7 +4,8 @@ set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project("StressUI"
project(
"StressUI"
LANGUAGES CXX
VERSION 0.2
)

View File

@ -1,11 +1,12 @@
#include "config.hpp"
#include <fstream>
#include <string>
#include <sstream>
#include <string>
#ifndef __CONFIG_FILE_HPP_
#define __CONFIG_FILE_HPP_
namespace cf {
const std::string g_configFile = std::string(getenv("HOME")) + "/.config/stressUI.cfg";
const std::string g_configFile =
std::string(getenv("HOME")) + "/.config/stressUI.cfg";
Config openConfig();
void closeConfig(Config *config);
std::string getLine(std::ifstream *file);

View File

@ -5,7 +5,8 @@
namespace en {
const extern std::string noColor = "The terminal doesn't support colors";
const extern std::string errorGenerico_1 = "How do you get here?";
const extern std::string errorGenerico_2 = "Just in case we drop you on the main menu";
const extern std::string errorGenerico_2 =
"Just in case we drop you on the main menu";
const extern std::string menuPrincipal = "Main Menu";
const extern std::string menuPrincipal_1 = "- Start Stress Test";
const extern std::string menuPrincipal_2 = "- Configurate";
@ -23,7 +24,8 @@ namespace en{
const extern std::string confHilosError = "Must introduce a number";
const extern std::string confTiempoError = "The time format must be HH:mm:ss";
const extern std::string confArchText_1 = "Autogenerated file by Stress_UI";
const extern std::string confArchText_2 = "Do not edit manually without knowing what you do";
}
const extern std::string confArchText_2 =
"Do not edit manually without knowing what you do";
} // namespace en
#endif // __EN_HPP_

View File

@ -5,7 +5,8 @@
namespace es {
const extern std::string noColor = "El terminal no soporta colores";
const extern std::string errorGenerico_1 = "¿Como has llegado aquí?";
const extern std::string errorGenerico_2 = "Por si acaso vamos al menú principal";
const extern std::string errorGenerico_2 =
"Por si acaso vamos al menú principal";
const extern std::string menuPrincipal = "Menú Principal";
const extern std::string menuPrincipal_1 = "- Iniciar Stress Test";
const extern std::string menuPrincipal_2 = "- Configurar";
@ -21,9 +22,11 @@ namespace es{
const extern std::string confHilosInput = "- Número de hilos\t> ";
const extern std::string confTiempoInput = "- Tiempo de ejecución\t> ";
const extern std::string confHilosError = "Se debe introducir un número";
const extern std::string confTiempoError = "El formato del tiempo debe ser HH:mm:ss";
const extern std::string confTiempoError =
"El formato del tiempo debe ser HH:mm:ss";
const extern std::string confArchText_1 = "Archivo autogenerado por Stress_UI";
const extern std::string confArchText_2 = "No editar manualmente sin saber lo que se hace";
}
const extern std::string confArchText_2 =
"No editar manualmente sin saber lo que se hace";
} // namespace es
#endif // __ES_HPP_

View File

@ -21,9 +21,11 @@ namespace gl{
const extern std::string confHilosInput = "- Número de fíos\t> ";
const extern std::string confTiempoInput = "- Tempo de execución\t> ";
const extern std::string confHilosError = "Debese introducir un número";
const extern std::string confTiempoError = "O formato do tempo debe ser HH:mm:ss";
const extern std::string confTiempoError =
"O formato do tempo debe ser HH:mm:ss";
const extern std::string confArchText_1 = "Arquivo autoxenerado por Stress_UI";
const extern std::string confArchText_2 = "Non editar manualmente sin saber o que se fai";
}
const extern std::string confArchText_2 =
"Non editar manualmente sin saber o que se fai";
} // namespace gl
#endif // __GL_HPP_

View File

@ -26,6 +26,6 @@ namespace txt{
extern std::string g_confArchText_2;
void inicializarIdioma(std::string idioma);
}
} // namespace txt
#endif // __TEXTOS_HPP_

View File

@ -12,9 +12,20 @@ namespace ui {
int8_t initUI(const int8_t *menu_principal, const int8_t *menu_error);
void closeUI();
std::vector<std::string> showCentralInputBox(std::vector<std::string> *textos, const int8_t *num_box, std::vector<std::string> *elems, const int8_t *color_error);
std::vector<std::string> showCentralInputBox(std::vector<std::string> *textos, const int8_t *num_box, std::vector<std::string> *elems, long title_size, const int8_t *color_error);
void showCenterMensaje(std::vector<std::string> *mensaje, const int8_t *menu_color);
std::vector<std::string> showCentralInputBox(std::vector<std::string> *textos,
const int8_t *num_box,
std::vector<std::string> *elems,
const int8_t *color_error);
std::vector<std::string> showCentralInputBox(std::vector<std::string> *textos,
const int8_t *num_box,
std::vector<std::string> *elems,
long title_size,
const int8_t *color_error);
void showCenterMensaje(std::vector<std::string> *mensaje,
const int8_t *menu_color);
void showTopTitle(const std::vector<std::string> *titulo);
} // namespace ui
#endif // __UI_HPP_

View File

@ -9,18 +9,11 @@ Config::Config(int8_t numHilos, std::string tiempo) {
// delete numHilos;
// delete tiempo;
// }
int8_t Config::getNumHilos() {
return numHilos;
}
std::string Config::getTiempo() {
return tiempo;
}
int8_t Config::getNumHilos() { return numHilos; }
void Config::setNumHilos(int8_t numHilos) {
Config::numHilos = numHilos;
}
std::string Config::getTiempo() { return tiempo; }
void Config::setTiempo(std::string tiempo) {
Config::tiempo = tiempo;
}
void Config::setNumHilos(int8_t numHilos) { Config::numHilos = numHilos; }
void Config::setTiempo(std::string tiempo) { Config::tiempo = tiempo; }

View File

@ -1,8 +1,8 @@
#include "configFile.hpp"
#include "textos.hpp"
#include "ui.hpp"
#include <locale.h>
#include <thread>
#include "configFile.hpp"
#include "ui.hpp"
#include "textos.hpp"
using namespace std;
@ -23,22 +23,28 @@ const int8_t MENU_TITULO = 9;
const int8_t PRIMER_INICIO = 10;
const vector<string> TITULO_PRINCIPAL = {
"____ ___ __ __ _____ ____ ___ ______ __ ____ _____ ______ _______ ____ ",
"/ ___| / _ \\| \\/ | ____| __ ) / _ \\| _ \\ \\ / / / ___|| ____| _ \\ \\ / / ____| _ \\ ",
"\\___ \\| | | | |\\/| | _| | _ \\| | | | | | \\ V / \\___ \\| _| | |_) \\ \\ / /| _| | |_) |",
" ___) | |_| | | | | |___| |_) | |_| | |_| || | ___) | |___| _ < \\ V / | |___| _ < ",
"|____/ \\___/|_| |_|_____|____/ \\___/|____/ |_| |____/|_____|_| \\_\\ \\_/ |_____|_| \\_\\",
"____ ___ __ __ _____ ____ ___ ______ __ ____ _____ ______ "
"_______ ____ ",
"/ ___| / _ \\| \\/ | ____| __ ) / _ \\| _ \\ \\ / / / ___|| ____| _ "
"\\ \\ / / ____| _ \\ ",
"\\___ \\| | | | |\\/| | _| | _ \\| | | | | | \\ V / \\___ \\| _| | "
"|_) \\ \\ / /| _| | |_) |",
" ___) | |_| | | | | |___| |_) | |_| | |_| || | ___) | |___| _ < \\ V "
"/ | |___| _ < ",
"|____/ \\___/|_| |_|_____|____/ \\___/|____/ |_| |____/|_____|_| \\_\\ "
"\\_/ |_____|_| \\_\\",
"",
"_______________________________________________________________________",
};
void userInterface(const int8_t *menu, Config *config);
void userInterface(const int8_t *menu, vector<string> *mensaje, Config *config);
void showMenu(vector<string> *menu_elems, const int8_t *num_menu, vector<string> *mensaje, Config *config);
void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config);
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
vector<string> *mensaje, Config *config);
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
Config *config);
int main(int argc, char *argv[]) {
txt::inicializarIdioma(setlocale(LC_ALL, ""));
if (ui::initUI(&MENU_PRINCIPAL, &MENU_ERROR) != 0) {
@ -62,11 +68,13 @@ void userInterface(const int8_t *menu, Config *config) {
userInterface(menu, &dummy, config);
}
void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *config) {
void userInterface(const int8_t *num_menu, vector<string> *mensaje,
Config *config) {
switch (*num_menu) {
case CONFIGURAR_MENU_PRINCIPAL:
case MENU_PRINCIPAL: {
vector<string> elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2, txt::g_menuPrincipal_3};
vector<string> elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2,
txt::g_menuPrincipal_3};
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config);
break;
}
@ -74,13 +82,16 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
/*TODO
*Lleva al menú principal
*/
vector<string> elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2, txt::g_menuPrincipal_3};
vector<string> elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2,
txt::g_menuPrincipal_3};
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config);
break;
}
case MENU_CONFIGURACION: {
vector<string> elem_menu = {txt::g_menuConfigurar_1, txt::g_menuConfigurar_2, txt::g_menuConfigurar_3, txt::g_menuConfigurar_4};
vector<string> elem_menu = {
txt::g_menuConfigurar_1, txt::g_menuConfigurar_2,
txt::g_menuConfigurar_3, txt::g_menuConfigurar_4};
showMenu(&elem_menu, num_menu, mensaje, config);
break;
}
@ -91,7 +102,9 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
vector<string> textos_init = {txt::g_confTodo + cf::g_configFile, "", ""};
vector<string> elemens = {txt::g_confHilosInput, txt::g_confTiempoInput};
ui::showTopTitle(&TITULO_PRINCIPAL);
vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size(), &MENU_ERROR);
vector<string> entrada =
ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens,
TITULO_PRINCIPAL.size(), &MENU_ERROR);
Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]);
config = &config2;
cf::saveConfig(config);
@ -100,9 +113,12 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
}
case CONFIGURAR_HILOS: {
vector<string> textos_init = {txt::g_confHilos + to_string(config->getNumHilos()), "", ""};
vector<string> textos_init = {
txt::g_confHilos + to_string(config->getNumHilos()), "", ""};
vector<string> elemens = {txt::g_confHilosInput};
vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size(), &MENU_ERROR);
vector<string> entrada =
ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens,
TITULO_PRINCIPAL.size(), &MENU_ERROR);
config->setNumHilos(atoi(entrada[0].c_str()));
cf::saveConfig(config);
userInterface(&MENU_CONFIGURACION, mensaje, config);
@ -110,9 +126,12 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
}
case CONFIGURAR_TIEMPO: {
vector<string> textos_init = {txt::g_confTiempo + config->getTiempo(), "", ""};
vector<string> textos_init = {txt::g_confTiempo + config->getTiempo(), "",
""};
vector<string> elemens = {txt::g_confTiempoInput};
vector<string> entrada = ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens, TITULO_PRINCIPAL.size(), &MENU_ERROR);
vector<string> entrada =
ui::showCentralInputBox(&textos_init, &CONFIGURAR_TODO, &elemens,
TITULO_PRINCIPAL.size(), &MENU_ERROR);
config->setTiempo(entrada[0]);
cf::saveConfig(config);
userInterface(&MENU_CONFIGURACION, mensaje, config);
@ -123,7 +142,8 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
/*TODO
*Lleva al menú principal
*/
vector<string> elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2, txt::g_menuPrincipal_3};
vector<string> elem_menu = {txt::g_menuPrincipal_1, txt::g_menuPrincipal_2,
txt::g_menuPrincipal_3};
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config);
break;
}
@ -141,7 +161,8 @@ void userInterface(const int8_t *num_menu, vector<string> *mensaje, Config *conf
}
}
void showMenu(vector<string> *menu_elems, const int8_t *num_menu, vector<string> *mensaje, Config *config) {
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
vector<string> *mensaje, Config *config) {
clear();
if (ui::g_mensaje) {
ui::showCenterMensaje(mensaje, &MENU_ERROR);
@ -149,11 +170,13 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu, vector<string>
showMenu(menu_elems, num_menu, config);
}
void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config) {
void showMenu(vector<string> *menu_elems, const int8_t *num_menu,
Config *config) {
size_t height = menu_elems->size();
attron(COLOR_PAIR(MENU_PRINCIPAL));
WINDOW *menuwin = newwin(height + 2, ui::g_menuWith, TITULO_PRINCIPAL.size() + 4, 2);
WINDOW *menuwin =
newwin(height + 2, ui::g_menuWith, TITULO_PRINCIPAL.size() + 4, 2);
box(menuwin, 0, 0);
refresh();
@ -186,7 +209,8 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config
}
if (menu_elems->at(i).length() < (ui::g_menuWith - 4)) {
for (int j = menu_elems->at(i).length(); j < (ui::g_menuWith - 4); j++) {
for (int j = menu_elems->at(i).length(); j < (ui::g_menuWith - 4);
j++) {
menu_elems->at(i).append(" ");
}

View File

@ -1,7 +1,7 @@
#include "textos.hpp"
#include "idiomas/en.hpp"
#include "idiomas/es.hpp"
#include "idiomas/gl.hpp"
#include "idiomas/en.hpp"
std::string txt::g_noColor;
std::string txt::g_errorGenerico_1;
@ -27,7 +27,6 @@ std::string txt::g_confArchText_2;
void txt::inicializarIdioma(std::string idioma) {
idioma = idioma.substr(0, idioma.find("_"));
if (idioma == "gl") {
using namespace gl;
txt::g_noColor = noColor;
@ -121,5 +120,4 @@ void txt::inicializarIdioma(std::string idioma){
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
}
}

View File

@ -51,11 +51,17 @@ void ui::showCenterMensaje(vector<string> *mensaje, const int8_t *menu_color) {
g_mensaje = false;
}
vector<string> ui::showCentralInputBox(std::vector<std::string> *textos, const int8_t *num_box, std::vector<std::string> *elems, const int8_t *color_error) {
vector<string> ui::showCentralInputBox(std::vector<std::string> *textos,
const int8_t *num_box,
std::vector<std::string> *elems,
const int8_t *color_error) {
return ui::showCentralInputBox(textos, num_box, elems, 0, color_error);
}
vector<string> ui::showCentralInputBox(vector<string> *textos, const int8_t *num_box, vector<string> *elems, long title_size, const int8_t *color_error) {
vector<string> ui::showCentralInputBox(vector<string> *textos,
const int8_t *num_box,
vector<string> *elems, long title_size,
const int8_t *color_error) {
vector<string> entrada;
int start_ver_window = 1;
@ -64,7 +70,8 @@ vector<string> ui::showCentralInputBox(vector<string> *textos, const int8_t *num
}
int height = ui::g_maxLines - (title_size + 4) - 1;
WINDOW *centralBOX = newwin(height, ui::g_maxCols - ui::g_menuWith - 4, start_ver_window, ui::g_menuWith + 2);
WINDOW *centralBOX = newwin(height, ui::g_maxCols - ui::g_menuWith - 4,
start_ver_window, ui::g_menuWith + 2);
box(centralBOX, 0, 0);
for (int i = 0; i < textos->size(); i++) {
@ -90,17 +97,20 @@ vector<string> ui::showCentralInputBox(vector<string> *textos, const int8_t *num
} else {
mvwprintw(centralBOX, i * 2 + 1 + textos->size(), 1, cleaner.c_str());
wattron(centralBOX, COLOR_PAIR(*color_error));
mvwprintw(centralBOX, i * 2 + textos->size(), 1, txt::g_confHilosError.c_str());
mvwprintw(centralBOX, i * 2 + textos->size(), 1,
txt::g_confHilosError.c_str());
wattroff(centralBOX, COLOR_PAIR(*color_error));
i--;
}
} else if (elems->at(i) == txt::g_confTiempoInput) {
if(regex_match(input,regex("^([0-1]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"))){
if (regex_match(input,
regex("^([0-1]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"))) {
entrada.push_back(input);
} else {
mvwprintw(centralBOX, i * 2 + 1 + textos->size(), 1, cleaner.c_str());
wattron(centralBOX, COLOR_PAIR(*color_error));
mvwprintw(centralBOX, i * 2 + textos->size(), 1, txt::g_confTiempoError.c_str());
mvwprintw(centralBOX, i * 2 + textos->size(), 1,
txt::g_confTiempoError.c_str());
wattroff(centralBOX, COLOR_PAIR(*color_error));
i--;
}
@ -119,7 +129,8 @@ void ui::showTopTitle(const vector<string> *titulo) {
attron(A_BOLD);
box(topTitleWin, 0, 0);
for (int i = 0; i < height; i++) {
mvwprintw(topTitleWin, i + 1, (g_maxCols - 4 - titulo->at(i).length()) / 2, titulo->at(i).c_str());
mvwprintw(topTitleWin, i + 1, (g_maxCols - 4 - titulo->at(i).length()) / 2,
titulo->at(i).c_str());
}
attroff(A_BOLD);
wrefresh(topTitleWin);