138 lines
4.0 KiB
C++
Executable File
138 lines
4.0 KiB
C++
Executable File
#include "ui.hpp"
|
|
#include "configFile.hpp"
|
|
#include "textos.hpp"
|
|
#include <regex>
|
|
|
|
using namespace std;
|
|
|
|
int ui::g_maxLines = 0;
|
|
int ui::g_maxCols = 0;
|
|
int ui::g_begLine = 0;
|
|
int ui::g_begCol = 0;
|
|
int ui::g_menuWith = 30;
|
|
bool ui::g_mensaje = false;
|
|
|
|
int8_t ui::initUI(const int8_t *menu_principal, const int8_t *menu_error) {
|
|
initscr();
|
|
noecho();
|
|
cbreak();
|
|
if (!has_colors()) {
|
|
printw(txt::g_noColor.c_str());
|
|
getch();
|
|
return -1;
|
|
}
|
|
start_color();
|
|
init_pair(*menu_principal, COLOR_WHITE, COLOR_BLACK);
|
|
init_pair(*menu_error, COLOR_RED, COLOR_BLACK);
|
|
curs_set(0);
|
|
getbegyx(stdscr, ui::g_begLine, ui::g_begCol);
|
|
getmaxyx(stdscr, ui::g_maxLines, ui::g_maxCols);
|
|
return 0;
|
|
}
|
|
|
|
void ui::closeUI() {
|
|
echo();
|
|
nocbreak();
|
|
curs_set(1);
|
|
endwin();
|
|
}
|
|
|
|
void ui::showCenterMensaje(vector<string> *mensaje, const int8_t *menu_color) {
|
|
int startLine = (g_maxLines - mensaje->size()) / 2;
|
|
|
|
attron(COLOR_PAIR(*menu_color));
|
|
for (int i = 0; i < mensaje->size(); i++) {
|
|
move(startLine + i, (g_maxCols - mensaje->at(i).length()) / 2);
|
|
printw(mensaje->at(i).c_str());
|
|
refresh();
|
|
}
|
|
|
|
attroff(COLOR_PAIR(*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) {
|
|
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> entrada;
|
|
int start_ver_window = 1;
|
|
|
|
if (title_size != 0) {
|
|
start_ver_window = title_size + 4;
|
|
}
|
|
|
|
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);
|
|
box(centralBOX, 0, 0);
|
|
|
|
for (int i = 0; i < textos->size(); i++) {
|
|
mvwprintw(centralBOX, i + 1, 1, textos->at(i).c_str());
|
|
}
|
|
|
|
wrefresh(centralBOX);
|
|
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 * 2 + 1 + textos->size(), 1, elems->at(i).c_str());
|
|
wrefresh(centralBOX);
|
|
wgetnstr(centralBOX, input, 10);
|
|
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 * 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());
|
|
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 * 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());
|
|
wattroff(centralBOX, COLOR_PAIR(*color_error));
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
curs_set(0);
|
|
noecho();
|
|
cbreak();
|
|
|
|
return entrada;
|
|
}
|
|
|
|
void ui::showTopTitle(const vector<string> *titulo) {
|
|
size_t height = titulo->size();
|
|
WINDOW *topTitleWin = newwin(height + 3, g_maxCols - 4, 1, 2);
|
|
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());
|
|
}
|
|
attroff(A_BOLD);
|
|
wrefresh(topTitleWin);
|
|
}
|