Init commit

This commit is contained in:
2020-10-20 14:16:46 +02:00
commit 7a3fa50503
8 changed files with 524 additions and 0 deletions

109
src/ui.cpp Normal file
View File

@@ -0,0 +1,109 @@
#include "ui.hpp"
#include "configFile.hpp"
#include <locale>
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) {
/*TODO hacer que la interfaz lea la localización*/
locale::global(locale("es_ES.utf8"));
initscr();
noecho();
cbreak();
if (!has_colors()) {
printw("El terminal no soporta colores");
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;
}
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);
}
void ui::showCentralInputBox(vector<string> *textos, const int8_t *num_box,
vector<string> *elems, long title_size) {
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);
for (int i = 0; i < elems->size(); i++) {
mvwprintw(centralBOX, i + 1 + textos->size(), 1, elems->at(i).c_str());
wrefresh(centralBOX);
char input[10];
wgetnstr(centralBOX, input, 10);
}
curs_set(0);
noecho();
cbreak();
// std::chrono::milliseconds timespan(10000); // or whatever
// std::this_thread::sleep_for(timespan);
}
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);
// wrefresh(topTitleWin);
for (int i = 0; i < height; i++) {
mvwprintw(topTitleWin, i + 1, (g_maxCols - 4 - titulo->at(i).length()) / 2,
titulo->at(i).c_str());
// wattroff(topTitleWin, A_REVERSE);
}
attroff(A_BOLD);
wrefresh(topTitleWin);
}