Compare commits
3 Commits
e92069c8db
...
4b7644bd4f
Author | SHA1 | Date | |
---|---|---|---|
4b7644bd4f | |||
6c8840b3e5 | |||
87768dedf4 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ compile_commands.json
|
||||
core*
|
||||
build
|
||||
log
|
||||
complaints
|
@ -13,7 +13,7 @@ inline constexpr auto hash_djb2a(const std::string_view sv) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
inline constexpr auto operator"" _sh(const char* str, size_t len) {
|
||||
inline constexpr auto operator""_sh(const char* str, size_t len) {
|
||||
return hash_djb2a(std::string_view{str, len});
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
#include <form.h>
|
||||
#include <ncurses.h>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <format>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "gameske_funkce.h"
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <form.h>
|
||||
#include <format>
|
||||
#include <ncurses.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define HEADER_COLOR_PAIR COLOR_RED
|
||||
#define FIELD_NAME_COLOR_PAIR 10
|
||||
@ -17,7 +17,7 @@ std::vector<allocation> editor_easy_allocated;
|
||||
|
||||
[[nodiscard]] std::string vytvorTrestniOznameni() {
|
||||
current_allocated = &editor_easy_allocated;
|
||||
auto trim = [](const char *str) -> std::string {
|
||||
auto trim = [](const char* str) -> std::string {
|
||||
std::string s(str);
|
||||
if (s.empty())
|
||||
return s;
|
||||
@ -40,26 +40,26 @@ std::vector<allocation> editor_easy_allocated;
|
||||
|
||||
// Nastavení barev
|
||||
start_color();
|
||||
init_pair(FIELD_NAME_COLOR_PAIR, COLOR_BLACK, COLOR_CYAN); // Popisky
|
||||
init_pair(INPUT_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK); // Vstupní pole
|
||||
init_pair(FIELD_NAME_COLOR_PAIR, COLOR_BLACK, COLOR_CYAN); // Popisky
|
||||
init_pair(INPUT_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK); // Vstupní pole
|
||||
|
||||
// Hlavní okno s rámečkem
|
||||
WINDOW *main_win = newwin(LINES - 4, COLS - 4, 2, 2);
|
||||
WINDOW* main_win = newwin(LINES - 4, COLS - 4, 2, 2);
|
||||
box(main_win, 0, 0);
|
||||
wrefresh(main_win);
|
||||
|
||||
// Okno pro popisky
|
||||
WINDOW *label_win = derwin(main_win, LINES - 8, 30, 1, 1);
|
||||
WINDOW* label_win = derwin(main_win, LINES - 8, 30, 1, 1);
|
||||
wbkgd(label_win, COLOR_PAIR(FIELD_NAME_COLOR_PAIR));
|
||||
|
||||
// Okno pro vstupní pole
|
||||
WINDOW *field_win = derwin(main_win, LINES - 8, COLS - 38, 1, 32);
|
||||
WINDOW* field_win = derwin(main_win, LINES - 8, COLS - 38, 1, 32);
|
||||
wbkgd(field_win, COLOR_PAIR(INPUT_COLOR_PAIR));
|
||||
keypad(field_win, TRUE);
|
||||
|
||||
// Definice polí
|
||||
struct FieldConfig {
|
||||
const char *label;
|
||||
const char* label;
|
||||
int height;
|
||||
int width;
|
||||
bool multiline;
|
||||
@ -84,18 +84,18 @@ std::vector<allocation> editor_easy_allocated;
|
||||
|
||||
// Vykreslení popisků
|
||||
int label_row = 0;
|
||||
for (const FieldConfig &cfg : field_configs) {
|
||||
for (const FieldConfig& cfg : field_configs) {
|
||||
mvwprintw(label_win, label_row, 0, "%s", cfg.label);
|
||||
label_row += cfg.height + 1;
|
||||
}
|
||||
wrefresh(label_win);
|
||||
|
||||
// Vytvoření formuláře
|
||||
std::vector<FIELD *> fields;
|
||||
std::vector<FIELD*> fields;
|
||||
int field_row = 0;
|
||||
|
||||
for (const FieldConfig &cfg : field_configs) {
|
||||
FIELD *field = new_field(cfg.height, cfg.width, field_row, 0, 0, 0);
|
||||
for (const FieldConfig& cfg : field_configs) {
|
||||
FIELD* field = new_field(cfg.height, cfg.width, field_row, 0, 0, 0);
|
||||
set_field_back(field, A_UNDERLINE | COLOR_PAIR(INPUT_COLOR_PAIR));
|
||||
field_opts_off(field, O_AUTOSKIP | O_STATIC);
|
||||
|
||||
@ -109,7 +109,7 @@ std::vector<allocation> editor_easy_allocated;
|
||||
}
|
||||
fields.push_back(nullptr);
|
||||
|
||||
FORM *form = new_form(&fields[0]);
|
||||
FORM* form = new_form(&fields[0]);
|
||||
set_form_win(form, field_win);
|
||||
set_form_sub(form, derwin(field_win, LINES - 10, COLS - 40, 1, 1));
|
||||
|
||||
@ -128,56 +128,56 @@ std::vector<allocation> editor_easy_allocated;
|
||||
bool exit_loop = false;
|
||||
while (!exit_loop && (ch = wgetch(field_win))) {
|
||||
switch (ch) {
|
||||
case KEY_F(10):
|
||||
exit_loop = true;
|
||||
break;
|
||||
case KEY_F(10):
|
||||
exit_loop = true;
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
form_driver(form, REQ_NEXT_FIELD);
|
||||
form_driver(form, REQ_END_LINE);
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
form_driver(form, REQ_PREV_FIELD);
|
||||
form_driver(form, REQ_END_LINE);
|
||||
break;
|
||||
|
||||
case KEY_LEFT:
|
||||
form_driver(form, REQ_PREV_CHAR);
|
||||
break;
|
||||
|
||||
case KEY_RIGHT:
|
||||
form_driver(form, REQ_NEXT_CHAR);
|
||||
break;
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
case 127:
|
||||
form_driver(form, REQ_DEL_PREV);
|
||||
break;
|
||||
|
||||
case KEY_DC:
|
||||
form_driver(form, REQ_DEL_CHAR);
|
||||
break;
|
||||
|
||||
case 10: // Enter
|
||||
if (field_configs[current_field(form)->index].multiline) {
|
||||
form_driver(form, REQ_NEW_LINE);
|
||||
} else {
|
||||
case KEY_DOWN:
|
||||
form_driver(form, REQ_NEXT_FIELD);
|
||||
}
|
||||
break;
|
||||
form_driver(form, REQ_END_LINE);
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
form_driver(form, REQ_NEXT_FIELD);
|
||||
break;
|
||||
case KEY_UP:
|
||||
form_driver(form, REQ_PREV_FIELD);
|
||||
form_driver(form, REQ_END_LINE);
|
||||
break;
|
||||
|
||||
case KEY_BTAB:
|
||||
form_driver(form, REQ_PREV_FIELD);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
form_driver(form, REQ_PREV_CHAR);
|
||||
break;
|
||||
|
||||
default:
|
||||
form_driver(form, ch);
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
form_driver(form, REQ_NEXT_CHAR);
|
||||
break;
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
case 127:
|
||||
form_driver(form, REQ_DEL_PREV);
|
||||
break;
|
||||
|
||||
case KEY_DC:
|
||||
form_driver(form, REQ_DEL_CHAR);
|
||||
break;
|
||||
|
||||
case 10: // Enter
|
||||
if (field_configs[current_field(form)->index].multiline) {
|
||||
form_driver(form, REQ_NEW_LINE);
|
||||
} else {
|
||||
form_driver(form, REQ_NEXT_FIELD);
|
||||
}
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
form_driver(form, REQ_NEXT_FIELD);
|
||||
break;
|
||||
|
||||
case KEY_BTAB:
|
||||
form_driver(form, REQ_PREV_FIELD);
|
||||
break;
|
||||
|
||||
default:
|
||||
form_driver(form, ch);
|
||||
break;
|
||||
}
|
||||
|
||||
// Ruční aktualizace všech oken
|
||||
@ -197,7 +197,7 @@ std::vector<allocation> editor_easy_allocated;
|
||||
// Úklid
|
||||
unpost_form(form);
|
||||
free_form(form);
|
||||
for (fieldnode *&f : fields)
|
||||
for (fieldnode*& f : fields)
|
||||
if (f)
|
||||
free_field(f);
|
||||
delwin(label_win);
|
||||
@ -208,29 +208,29 @@ std::vector<allocation> editor_easy_allocated;
|
||||
|
||||
// Aktuální datum
|
||||
std::time_t t = std::time(nullptr);
|
||||
std::tm *now = std::localtime(&t);
|
||||
std::tm* now = std::localtime(&t);
|
||||
char date_str[100];
|
||||
std::strftime(date_str, sizeof(date_str), "%d.%m.%Y", now);
|
||||
|
||||
auto comp_args =
|
||||
std::make_format_args(field_values[0], // Jméno a příjmení odesílatele
|
||||
field_values[1], // Adresa odesílatele
|
||||
field_values[2], // Telefon odesílatele
|
||||
field_values[3], // Email odesílatele
|
||||
std::make_format_args(field_values[0], // Jméno a příjmení odesílatele
|
||||
field_values[1], // Adresa odesílatele
|
||||
field_values[2], // Telefon odesílatele
|
||||
field_values[3], // Email odesílatele
|
||||
|
||||
field_values[7], // Jméno a příjmení adresáta
|
||||
field_values[10], // Adresa adresáta
|
||||
field_values[11], // Telefon adresáta
|
||||
field_values[12], // Email adresáta
|
||||
field_values[4], // Jméno a příjmení adresáta
|
||||
field_values[5], // Adresa adresáta
|
||||
field_values[6], // Telefon adresáta
|
||||
field_values[7], // Email adresáta
|
||||
|
||||
date_str, // Aktuální datum
|
||||
field_values[4], // Místo činu
|
||||
field_values[5], // Datum činu
|
||||
date_str, // Aktuální datum
|
||||
field_values[8], // Místo činu
|
||||
field_values[9], // Datum činu
|
||||
|
||||
field_values[6], // Popis činu
|
||||
field_values[8], // Důkazy
|
||||
field_values[9], // Další informace
|
||||
field_values[0] // Jméno pro podpis
|
||||
field_values[10], // Popis činu
|
||||
field_values[11], // Důkazy
|
||||
field_values[12], // Další informace
|
||||
field_values[0] // Jméno pro podpis
|
||||
);
|
||||
|
||||
std::string complaint =
|
||||
|
110
src/menu.cpp
110
src/menu.cpp
@ -1,3 +1,15 @@
|
||||
#include <curses.h>
|
||||
#include <menu.h>
|
||||
#include <ncurses.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "const.h"
|
||||
#include "cups.h"
|
||||
#include "editor_easy.h"
|
||||
@ -5,21 +17,9 @@
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
#include "types.h"
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <curses.h>
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <menu.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
std::vector<allocation> main_menu_allocated;
|
||||
|
||||
const char *choices[] = {"paradox", "kompromis", "Stereotyp", "Žena"};
|
||||
const char *date[] = {"2023-10-01", "2023-10-02", "2023-10-03", "2023-10-04"};
|
||||
const char *choices2[] = {"PRINT", "EDIT", "DELETE", "Žena"};
|
||||
|
||||
#define COMPLAINTS_DIR "complaints"
|
||||
void menu() {
|
||||
current_allocated = &main_menu_allocated;
|
||||
/* Initialize curses */
|
||||
@ -29,24 +29,40 @@ 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);
|
||||
}
|
||||
async_clock_init();
|
||||
|
||||
/* Create items */
|
||||
size_t n_choices = ARRAY_SIZE(choices);
|
||||
// Create items
|
||||
complete_menu main_menu = {nullptr, nullptr, 0, nullptr};
|
||||
main_menu_allocated.push_back({COMPLETE_MENU_TYPE, &main_menu, 1});
|
||||
|
||||
main_menu.items = new ITEM *[ARRAY_SIZE(choices) + 1];
|
||||
main_menu.items_size = ARRAY_SIZE(choices) + 1;
|
||||
for (size_t i = 0; i < n_choices; ++i) {
|
||||
main_menu.items[i] = new_item(choices[i], date[i]);
|
||||
std::vector<ITEM*> items;
|
||||
if (std::filesystem::exists(COMPLAINTS_DIR)) {
|
||||
for (const auto& directroy_entry :
|
||||
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
|
||||
if (directroy_entry.is_regular_file()) {
|
||||
std::string name_date[2];
|
||||
std::stringstream ssfn(directroy_entry.path().filename().string());
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
std::getline(ssfn, name_date[i], '_');
|
||||
}
|
||||
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];
|
||||
main_menu_allocated.push_back({GENERIC_TYPE, date, 1});
|
||||
strcpy(name, name_date[0].c_str());
|
||||
strcpy(date, name_date[1].c_str());
|
||||
items.push_back(new_item(name, date));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::filesystem::create_directory(COMPLAINTS_DIR);
|
||||
}
|
||||
main_menu.items[n_choices] = nullptr;
|
||||
items.push_back(nullptr);
|
||||
main_menu.items = items.data();
|
||||
|
||||
/* Crate menu */
|
||||
main_menu.menu = new_menu(main_menu.items);
|
||||
@ -79,33 +95,33 @@ 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();
|
||||
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;
|
||||
refresh();
|
||||
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 ':':
|
||||
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;
|
||||
}
|
||||
}
|
||||
redrawwin(main_menu.win);
|
||||
wrefresh(main_menu.win);
|
||||
|
Loading…
x
Reference in New Issue
Block a user