preparation for file integration

This commit is contained in:
PoliEcho 2025-05-28 15:15:32 +02:00
parent ff9303861a
commit 0a07589e0e
5 changed files with 60 additions and 44 deletions

View File

@ -1,5 +1,6 @@
#include "gameske_funkce.h"
#include "memory.h"
#include "strings.h"
#include <chrono>
#include <clocale>
#include <cstddef>
@ -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);

View File

@ -1,3 +1,4 @@
#include "strings.h"
#include <ncurses.h>
#include <string>
@ -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();

View File

@ -1,11 +1,3 @@
#include <curses.h>
#include <menu.h>
#include <ncurses.h>
#include <cstdint>
#include <cstring>
#include <filesystem>
#include <iostream>
#include <vector>
#include "const.h"
#include "cups.h"
#include "editor_easy.h"
@ -13,6 +5,15 @@
#include "memory.h"
#include "strings.h"
#include "types.h"
#include <cstdint>
#include <cstring>
#include <curses.h>
#include <filesystem>
#include <iostream>
#include <menu.h>
#include <ncurses.h>
#include <string>
#include <vector>
std::vector<allocation> 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<ITEM*> items;
std::vector<ITEM *> 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);

View File

@ -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;

View File

@ -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;