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,10 +4,11 @@ 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
)
)
add_library(
ui

View File

@ -2,15 +2,15 @@
#ifndef __CONFIG_HPP_
#define __CONFIG_HPP_
class Config {
private:
int8_t numHilos;
std::string tiempo;
private:
int8_t numHilos;
std::string tiempo;
public:
Config(int8_t numHilos, std::string tiempo);
int8_t getNumHilos();
std::string getTiempo();
void setNumHilos(int8_t numHilos);
void setTiempo(std::string tiempo);
public:
Config(int8_t numHilos, std::string tiempo);
int8_t getNumHilos();
std::string getTiempo();
void setNumHilos(int8_t numHilos);
void setTiempo(std::string tiempo);
};
#endif // __CONFIG_HPP_

View File

@ -1,15 +1,16 @@
#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";
Config openConfig();
void closeConfig(Config *config);
std::string getLine(std::ifstream *file);
void saveConfig(Config *config);
void escribirText(std::ofstream *file, std::string *text, int numSpcs);
const std::string g_configFile =
std::string(getenv("HOME")) + "/.config/stressUI.cfg";
Config openConfig();
void closeConfig(Config *config);
std::string getLine(std::ifstream *file);
void saveConfig(Config *config);
void escribirText(std::ofstream *file, std::string *text, int numSpcs);
} // namespace cf
#endif // __CONFIG_FILE_HPP_

View File

@ -2,28 +2,30 @@
#ifndef __EN_HPP_
#define __EN_HPP_
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 menuPrincipal = "Main Menu";
const extern std::string menuPrincipal_1 = "- Start Stress Test";
const extern std::string menuPrincipal_2 = "- Configurate";
const extern std::string menuPrincipal_3 = "- Exit";
const extern std::string menuConfigurar = "Configuration";
const extern std::string menuConfigurar_1 = "- Configurate all";
const extern std::string menuConfigurar_2 = "- Number of threads";
const extern std::string menuConfigurar_3 = "- Time";
const extern std::string menuConfigurar_4 = "- Main Menu";
const extern std::string confTodo = "All the configuration will be write in ";
const extern std::string confHilos = "Current number of threads > ";
const extern std::string confTiempo = "Current execution time > ";
const extern std::string confHilosInput = "- Number of threads\t> ";
const extern std::string confTiempoInput = "- Execution time\t> ";
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";
}
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 menuPrincipal = "Main Menu";
const extern std::string menuPrincipal_1 = "- Start Stress Test";
const extern std::string menuPrincipal_2 = "- Configurate";
const extern std::string menuPrincipal_3 = "- Exit";
const extern std::string menuConfigurar = "Configuration";
const extern std::string menuConfigurar_1 = "- Configurate all";
const extern std::string menuConfigurar_2 = "- Number of threads";
const extern std::string menuConfigurar_3 = "- Time";
const extern std::string menuConfigurar_4 = "- Main Menu";
const extern std::string confTodo = "All the configuration will be write in ";
const extern std::string confHilos = "Current number of threads > ";
const extern std::string confTiempo = "Current execution time > ";
const extern std::string confHilosInput = "- Number of threads\t> ";
const extern std::string confTiempoInput = "- Execution time\t> ";
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";
} // namespace en
#endif // __EN_HPP_

View File

@ -2,28 +2,31 @@
#ifndef __ES_HPP_
#define __ES_HPP_
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 menuPrincipal = "Menú Principal";
const extern std::string menuPrincipal_1 = "- Iniciar Stress Test";
const extern std::string menuPrincipal_2 = "- Configurar";
const extern std::string menuPrincipal_3 = "- Salir";
const extern std::string menuConfigurar = "Configuración";
const extern std::string menuConfigurar_1 = "- Configurar todo";
const extern std::string menuConfigurar_2 = "- Número de hilos";
const extern std::string menuConfigurar_3 = "- Tiempo";
const extern std::string menuConfigurar_4 = "- Menú principal";
const extern std::string confTodo = "Toda la configuración se escribirá en ";
const extern std::string confHilos = "Número de hilos actuales > ";
const extern std::string confTiempo = "Tiempo actual > ";
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 confArchText_1 = "Archivo autogenerado por Stress_UI";
const extern std::string confArchText_2 = "No editar manualmente sin saber lo que se hace";
}
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 menuPrincipal = "Menú Principal";
const extern std::string menuPrincipal_1 = "- Iniciar Stress Test";
const extern std::string menuPrincipal_2 = "- Configurar";
const extern std::string menuPrincipal_3 = "- Salir";
const extern std::string menuConfigurar = "Configuración";
const extern std::string menuConfigurar_1 = "- Configurar todo";
const extern std::string menuConfigurar_2 = "- Número de hilos";
const extern std::string menuConfigurar_3 = "- Tiempo";
const extern std::string menuConfigurar_4 = "- Menú principal";
const extern std::string confTodo = "Toda la configuración se escribirá en ";
const extern std::string confHilos = "Número de hilos actuales > ";
const extern std::string confTiempo = "Tiempo actual > ";
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 confArchText_1 = "Archivo autogenerado por Stress_UI";
const extern std::string confArchText_2 =
"No editar manualmente sin saber lo que se hace";
} // namespace es
#endif // __ES_HPP_

View File

@ -2,28 +2,30 @@
#ifndef __GL_HPP_
#define __GL_HPP_
namespace gl{
const extern std::string noColor = "O terminal non soporta cores";
const extern std::string errorGenerico_1 = "Como chegaches aquí?";
const extern std::string errorGenerico_2 = "Por si acaso imos ó 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";
const extern std::string menuPrincipal_3 = "- Saír";
const extern std::string menuConfigurar = "Configuración";
const extern std::string menuConfigurar_1 = "- Configurar todo";
const extern std::string menuConfigurar_2 = "- Número de fíos";
const extern std::string menuConfigurar_3 = "- Tempo";
const extern std::string menuConfigurar_4 = "- Menú principal";
const extern std::string confTodo = "Toda a configuración escribirase en ";
const extern std::string confHilos = "Número de fíos actuáis > ";
const extern std::string confTiempo = "Tempo de execución actual > ";
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 confArchText_1 = "Arquivo autoxenerado por Stress_UI";
const extern std::string confArchText_2 = "Non editar manualmente sin saber o que se fai";
}
namespace gl {
const extern std::string noColor = "O terminal non soporta cores";
const extern std::string errorGenerico_1 = "Como chegaches aquí?";
const extern std::string errorGenerico_2 = "Por si acaso imos ó 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";
const extern std::string menuPrincipal_3 = "- Saír";
const extern std::string menuConfigurar = "Configuración";
const extern std::string menuConfigurar_1 = "- Configurar todo";
const extern std::string menuConfigurar_2 = "- Número de fíos";
const extern std::string menuConfigurar_3 = "- Tempo";
const extern std::string menuConfigurar_4 = "- Menú principal";
const extern std::string confTodo = "Toda a configuración escribirase en ";
const extern std::string confHilos = "Número de fíos actuáis > ";
const extern std::string confTiempo = "Tempo de execución actual > ";
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 confArchText_1 = "Arquivo autoxenerado por Stress_UI";
const extern std::string confArchText_2 =
"Non editar manualmente sin saber o que se fai";
} // namespace gl
#endif // __GL_HPP_

View File

@ -2,30 +2,30 @@
#ifndef __TEXTOS_HPP_
#define __TEXTOS_HPP_
namespace txt{
extern std::string g_noColor;
extern std::string g_errorGenerico_1;
extern std::string g_errorGenerico_2;
extern std::string g_menuPrincipal;
extern std::string g_menuPrincipal_1;
extern std::string g_menuPrincipal_2;
extern std::string g_menuPrincipal_3;
extern std::string g_menuConfigurar;
extern std::string g_menuConfigurar_1;
extern std::string g_menuConfigurar_2;
extern std::string g_menuConfigurar_3;
extern std::string g_menuConfigurar_4;
extern std::string g_confTodo;
extern std::string g_confHilos;
extern std::string g_confTiempo;
extern std::string g_confHilosInput;
extern std::string g_confTiempoInput;
extern std::string g_confHilosError;
extern std::string g_confTiempoError;
extern std::string g_confArchText_1;
extern std::string g_confArchText_2;
namespace txt {
extern std::string g_noColor;
extern std::string g_errorGenerico_1;
extern std::string g_errorGenerico_2;
extern std::string g_menuPrincipal;
extern std::string g_menuPrincipal_1;
extern std::string g_menuPrincipal_2;
extern std::string g_menuPrincipal_3;
extern std::string g_menuConfigurar;
extern std::string g_menuConfigurar_1;
extern std::string g_menuConfigurar_2;
extern std::string g_menuConfigurar_3;
extern std::string g_menuConfigurar_4;
extern std::string g_confTodo;
extern std::string g_confHilos;
extern std::string g_confTiempo;
extern std::string g_confHilosInput;
extern std::string g_confTiempoInput;
extern std::string g_confHilosError;
extern std::string g_confTiempoError;
extern std::string g_confArchText_1;
extern std::string g_confArchText_2;
void inicializarIdioma(std::string idioma);
}
void inicializarIdioma(std::string idioma);
} // namespace txt
#endif // __TEXTOS_HPP_

View File

@ -5,16 +5,27 @@
#define __UI_HPP_
namespace ui {
extern int g_maxLines, g_maxCols, g_begCol, g_begLine, g_menuWith;
//int8_t error;
extern bool g_mensaje;
extern int g_maxLines, g_maxCols, g_begCol, g_begLine, g_menuWith;
// int8_t error;
extern bool g_mensaje;
int8_t initUI(const int8_t *menu_principal, const int8_t *menu_error);
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);
void showTopTitle(const std::vector<std::string> *titulo);
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);
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,86 +68,101 @@ 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};
showMenu(&elem_menu, &MENU_PRINCIPAL, mensaje, config);
break;
}
case MENU_INICIAR_STRESS: {
/*TODO
*Lleva al menú principal
*/
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 CONFIGURAR_MENU_PRINCIPAL:
case MENU_PRINCIPAL: {
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_INICIAR_STRESS: {
/*TODO
*Lleva al menú principal
*/
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};
showMenu(&elem_menu, num_menu, 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};
showMenu(&elem_menu, num_menu, mensaje, config);
break;
}
case CONFIGURAR_TODO:
case PRIMER_INICIO: {
case CONFIGURAR_TODO:
case PRIMER_INICIO: {
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);
Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]);
config = &config2;
cf::saveConfig(config);
userInterface(&MENU_PRINCIPAL, mensaje, config);
break;
}
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);
Config config2 = Config(atoi(entrada[0].c_str()), entrada[1]);
config = &config2;
cf::saveConfig(config);
userInterface(&MENU_PRINCIPAL, mensaje, config);
break;
}
case CONFIGURAR_HILOS: {
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);
config->setNumHilos(atoi(entrada[0].c_str()));
cf::saveConfig(config);
userInterface(&MENU_CONFIGURACION, mensaje, config);
break;
}
case CONFIGURAR_HILOS: {
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);
config->setNumHilos(atoi(entrada[0].c_str()));
cf::saveConfig(config);
userInterface(&MENU_CONFIGURACION, mensaje, config);
break;
}
case CONFIGURAR_TIEMPO: {
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);
config->setTiempo(entrada[0]);
cf::saveConfig(config);
userInterface(&MENU_CONFIGURACION, mensaje, config);
break;
}
case CONFIGURAR_TIEMPO: {
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);
config->setTiempo(entrada[0]);
cf::saveConfig(config);
userInterface(&MENU_CONFIGURACION, mensaje, config);
break;
}
case MENU_TITULO: {
/*TODO
*Lleva al menú principal
*/
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_TITULO: {
/*TODO
*Lleva al menú principal
*/
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 SALIR: {
break;
}
case SALIR: {
break;
}
default: {
ui::g_mensaje = true;
*mensaje = {txt::g_errorGenerico_1, txt::g_errorGenerico_2};
userInterface(&MENU_PRINCIPAL, mensaje, config);
break;
}
default: {
ui::g_mensaje = true;
*mensaje = {txt::g_errorGenerico_1, txt::g_errorGenerico_2};
userInterface(&MENU_PRINCIPAL, mensaje, config);
break;
}
}
}
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();
@ -168,15 +191,15 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config
switch (*num_menu) {
case MENU_PRINCIPAL: {
mvwprintw(menuwin, 0, 1, txt::g_menuPrincipal.c_str());
break;
}
case MENU_PRINCIPAL: {
mvwprintw(menuwin, 0, 1, txt::g_menuPrincipal.c_str());
break;
}
case MENU_CONFIGURACION: {
mvwprintw(menuwin, 0, 1, txt::g_menuConfigurar.c_str());
break;
}
case MENU_CONFIGURACION: {
mvwprintw(menuwin, 0, 1, txt::g_menuConfigurar.c_str());
break;
}
}
while (true) {
@ -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(" ");
}
@ -221,22 +245,22 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config
choice = wgetch(menuwin);
switch (choice) {
case KEY_UP: {
if (highlight > 0) {
highlight--;
}
break;
case KEY_UP: {
if (highlight > 0) {
highlight--;
}
case KEY_DOWN: {
if ((highlight + 1) < height) {
highlight++;
}
break;
break;
}
case KEY_DOWN: {
if ((highlight + 1) < height) {
highlight++;
}
break;
}
default: {
break;
}
default: {
break;
}
}
if (choice == 10) {
@ -245,14 +269,14 @@ void showMenu(vector<string> *menu_elems, const int8_t *num_menu, Config *config
}
switch (*num_menu) {
case MENU_PRINCIPAL: {
highlight++;
break;
}
case MENU_CONFIGURACION: {
highlight = highlight + 4;
break;
}
case MENU_PRINCIPAL: {
highlight++;
break;
}
case MENU_CONFIGURACION: {
highlight = highlight + 4;
break;
}
}
attroff(COLOR_PAIR(MENU_PRINCIPAL));

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;
@ -25,101 +25,99 @@ std::string txt::g_confTiempoError;
std::string txt::g_confArchText_1;
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;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
}else if(idioma == "es"){
using namespace es;
txt::g_noColor = noColor;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
}else if(idioma == "en"){
using namespace en;
txt::g_noColor = noColor;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
}else{
using namespace en;
txt::g_noColor = noColor;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
}
void txt::inicializarIdioma(std::string idioma) {
idioma = idioma.substr(0, idioma.find("_"));
if (idioma == "gl") {
using namespace gl;
txt::g_noColor = noColor;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
} else if (idioma == "es") {
using namespace es;
txt::g_noColor = noColor;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
} else if (idioma == "en") {
using namespace en;
txt::g_noColor = noColor;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
txt::g_confArchText_1 = confArchText_1;
txt::g_confArchText_2 = confArchText_2;
} else {
using namespace en;
txt::g_noColor = noColor;
txt::g_errorGenerico_1 = errorGenerico_1;
txt::g_errorGenerico_2 = errorGenerico_2;
txt::g_menuPrincipal = menuPrincipal;
txt::g_menuPrincipal_1 = menuPrincipal_1;
txt::g_menuPrincipal_2 = menuPrincipal_2;
txt::g_menuPrincipal_3 = menuPrincipal_3;
txt::g_menuConfigurar = menuConfigurar;
txt::g_menuConfigurar_1 = menuConfigurar_1;
txt::g_menuConfigurar_2 = menuConfigurar_2;
txt::g_menuConfigurar_3 = menuConfigurar_3;
txt::g_menuConfigurar_4 = menuConfigurar_4;
txt::g_confTodo = confTodo;
txt::g_confHilos = confHilos;
txt::g_confTiempo = confTiempo;
txt::g_confHilosInput = confHilosInput;
txt::g_confTiempoInput = confTiempoInput;
txt::g_confHilosError = confHilosError;
txt::g_confTiempoError = confTiempoError;
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++) {
@ -83,24 +90,27 @@ vector<string> ui::showCentralInputBox(vector<string> *textos, const int8_t *num
mvwprintw(centralBOX, i * 2 + 1 + textos->size(), 1, elems->at(i).c_str());
wrefresh(centralBOX);
wgetnstr(centralBOX, input, 10);
if (elems->at(i) == txt::g_confHilosInput){
if (elems->at(i) == txt::g_confHilosInput) {
regex integer_expr("(\\+|-)?[[:digit:]]+");
if(regex_match(input, integer_expr)){
if (regex_match(input, integer_expr)) {
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_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]$"))){
} 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]$"))) {
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);