diff --git a/src/gameske_funkce.cpp b/src/gameske_funkce.cpp index a08d096..591a7d7 100644 --- a/src/gameske_funkce.cpp +++ b/src/gameske_funkce.cpp @@ -1,5 +1,6 @@ #include "gameske_funkce.h" #include "memory.h" +#include "strings.h" #include #include #include @@ -104,7 +105,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, refresh(); } -std::string spawncmd() { +std::string spawncmd(const std::string prompt) { char cmd[100] = {0}; int pos = 0; int ch; @@ -115,7 +116,7 @@ std::string spawncmd() { keypad(cmd_win, TRUE); box(cmd_win, 0, 0); - mvwprintw(cmd_win, 1, 1, "Command: "); + mvwprintw(cmd_win, 1, 1, "%s: ", prompt.c_str()); curs_set(1); wrefresh(cmd_win); diff --git a/src/gameske_funkce.h b/src/gameske_funkce.h index 0c786d9..fdb65a1 100644 --- a/src/gameske_funkce.h +++ b/src/gameske_funkce.h @@ -1,3 +1,4 @@ +#include "strings.h" #include #include @@ -12,7 +13,7 @@ size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char **choices, void print_in_middle(WINDOW *win, int starty, int startx, int width, const char *string, chtype color); -std::string spawncmd(); +std::string spawncmd(const std::string prompt = loc_strings->command); void async_clock_init(); diff --git a/src/menu.cpp b/src/menu.cpp index 6f4683f..1f780b1 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -1,11 +1,3 @@ -#include -#include -#include -#include -#include -#include -#include -#include #include "const.h" #include "cups.h" #include "editor_easy.h" @@ -13,6 +5,15 @@ #include "memory.h" #include "strings.h" #include "types.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include std::vector main_menu_allocated; #define COMPLAINTS_DIR "complaints" @@ -25,7 +26,7 @@ void menu() { start_color(); cbreak(); noecho(); - curs_set(0); // Makes cursor invisible + curs_set(0); // Makes cursor invisible keypad(stdscr, TRUE); for (uint8_t i = 0; i < 8; i++) { init_pair(i, i, COLOR_BLACK); @@ -36,9 +37,9 @@ void menu() { complete_menu main_menu = {nullptr, nullptr, 0, nullptr}; main_menu_allocated.push_back({COMPLETE_MENU_TYPE, &main_menu, 1}); { - std::vector items; + std::vector items; if (std::filesystem::exists(COMPLAINTS_DIR)) { - for (const auto& directroy_entry : + for (const auto &directroy_entry : std::filesystem::directory_iterator(COMPLAINTS_DIR)) { if (directroy_entry.is_regular_file()) { std::string name_date[2]; @@ -46,9 +47,9 @@ void menu() { for (uint8_t i = 0; i < 2; i++) { std::getline(ssfn, name_date[i], '_'); } - char* name = new char[name_date[0].length() + 1]; + char *name = new char[name_date[0].length() + 1]; main_menu_allocated.push_back({GENERIC_TYPE, name, 1}); - char* date = new char[name_date[1].length() + 1]; + char *date = new char[name_date[1].length() + 1]; main_menu_allocated.push_back({GENERIC_TYPE, date, 1}); strcpy(name, name_date[0].c_str()); strcpy(date, name_date[1].c_str()); @@ -59,8 +60,8 @@ void menu() { std::filesystem::create_directory(COMPLAINTS_DIR); } items.push_back(nullptr); - main_menu.items = new ITEM*[items.size()]; - memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM*))); + main_menu.items = new ITEM *[items.size()]; + memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM *))); } /* Crate menu */ @@ -94,33 +95,40 @@ void menu() { int c; while ((c = wgetch(main_menu.win)) != KEY_F(1)) { switch (c) { - case KEY_DOWN: - menu_driver(main_menu.menu, REQ_DOWN_ITEM); - break; - case KEY_UP: - menu_driver(main_menu.menu, REQ_UP_ITEM); - break; - case 10: + case KEY_DOWN: + menu_driver(main_menu.menu, REQ_DOWN_ITEM); + break; + case KEY_UP: + menu_driver(main_menu.menu, REQ_UP_ITEM); + break; + case 10: - refresh(); + refresh(); + break; + case ':': + switch (hash_djb2a(spawncmd())) { + case "print"_sh: + case "p"_sh: + // DONT FORGET TO PRINT ACTUAL DOCUMENT + printDocument("test"); + current_allocated = &main_menu_allocated; break; - case ':': - switch (hash_djb2a(spawncmd())) { - case "print"_sh: - case "p"_sh: - // DONT FORGET TO PRINT ACTUAL DOCUMENT - printDocument("test"); - current_allocated = &main_menu_allocated; - break; - case "easy_edit"_sh: - case "ee"_sh: - std::clog << vytvorTrestniOznameni(); - break; - default: - print_in_middle(main_menu.win, 10, 0, 40, - loc_strings->unknown_command, COLOR_PAIR(1)); - break; + case "easy_edit"_sh: + case "ee"_sh: { + std::string name = spawncmd("Reference Name"); + if (name == "") { + print_in_middle(main_menu.win, 10, 0, 40, + loc_strings->unknown_command, COLOR_PAIR(1)); } + + std::clog << vytvorTrestniOznameni(); + break; + } + default: + print_in_middle(main_menu.win, 10, 0, 40, loc_strings->unknown_command, + COLOR_PAIR(1)); + break; + } } redrawwin(main_menu.win); wrefresh(main_menu.win); diff --git a/src/strings.cpp b/src/strings.cpp index 0685304..5a4c9bd 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -74,7 +74,9 @@ I request the Police of the Czech Republic to: Signature of the complainant: {0} *This is not a legal document, but only a template for informational purposes. For legal advice, please consult a qualified attorney.* -)"}; +)", + .command = "Command", + .invalid_input = "Invalid input"}; constexpr strings czech_strings{ .invalid_option = "Neplatná volba: ", @@ -148,6 +150,8 @@ Dne {9} v místě {10}. Podpis oznamovatele: {0} *Toto není právní dokument, ale pouze vzor pro informativní účely. Pro právní poradenství se obraťte na kvalifikovaného právníka.* -)"}; +)", + .command = "Příkaz", + .invalid_input = "Neplatný vstup"}; const strings *loc_strings; \ No newline at end of file diff --git a/src/strings.h b/src/strings.h index f1ae63f..d1c68ff 100644 --- a/src/strings.h +++ b/src/strings.h @@ -34,6 +34,8 @@ typedef struct { const char *enter_all_information_and_press_f10; const char *criminal_complaint_template; + const char *command; + const char *invalid_input; } strings; extern const strings english_strings;