Implentación de control de entrada. Arregla #2
Signed-off-by: somebody_master <somebody_master@somebodyserver.mooo.com> Se ha implementado el control de entrada por teclado en la configuración para asegurar que se introducen datos adecuados. Se usan expresiones regulares, mediante la librería regex, para conseguir tal efecto.
This commit is contained in:
35
src/ui.cpp
35
src/ui.cpp
@@ -1,6 +1,7 @@
|
||||
#include "ui.hpp"
|
||||
#include "configFile.hpp"
|
||||
#include "textos.hpp"
|
||||
#include <regex>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -51,11 +52,11 @@ void ui::showCenterMensaje(vector<string> *mensaje, const int8_t *menu_color) {
|
||||
g_mensaje = false;
|
||||
}
|
||||
|
||||
void ui::showCentralInputBox(std::vector<std::string> *textos, const int8_t *num_box, std::vector<std::string> *elems) {
|
||||
ui::showCentralInputBox(textos, num_box, elems, 0);
|
||||
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) {
|
||||
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;
|
||||
|
||||
@@ -75,12 +76,36 @@ vector<string> ui::showCentralInputBox(vector<string> *textos, const int8_t *num
|
||||
echo();
|
||||
nocbreak();
|
||||
curs_set(1);
|
||||
char input[10];
|
||||
string cleaner;
|
||||
|
||||
for (int i = 0; i < elems->size(); i++) {
|
||||
cleaner = elems->at(i) + " ";
|
||||
mvwprintw(centralBOX, i + 1 + textos->size(), 1, elems->at(i).c_str());
|
||||
wrefresh(centralBOX);
|
||||
char input[10];
|
||||
wgetnstr(centralBOX, input, 10);
|
||||
entrada.push_back(input);
|
||||
if (elems->at(i) == txt::g_confHilosInput){
|
||||
regex integer_expr("(\\+|-)?[[:digit:]]+");
|
||||
if(regex_match(input, integer_expr)){
|
||||
entrada.push_back(input);
|
||||
} else {
|
||||
mvwprintw(centralBOX, i + 1 + textos->size(), 1, cleaner.c_str());
|
||||
wattron(centralBOX, COLOR_PAIR(*color_error));
|
||||
mvwprintw(centralBOX, i + 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]$"))){
|
||||
entrada.push_back(input);
|
||||
} else {
|
||||
mvwprintw(centralBOX, i + 1 + textos->size(), 1, cleaner.c_str());
|
||||
wattron(centralBOX, COLOR_PAIR(*color_error));
|
||||
mvwprintw(centralBOX, i + textos->size(), 1, txt::g_confTiempoError.c_str());
|
||||
wattroff(centralBOX, COLOR_PAIR(*color_error));
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
curs_set(0);
|
||||
noecho();
|
||||
|
||||
Reference in New Issue
Block a user