Compare commits
6 Commits
bf02560cdd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e4784cfaa | |||
| e6961d6d6d | |||
| 00f261696f | |||
| d330878f8a | |||
| 30c8ad2ca7 | |||
| edd21acaa5 |
@@ -6,10 +6,10 @@ jobs:
|
|||||||
runs-on: arch
|
runs-on: arch
|
||||||
steps:
|
steps:
|
||||||
- name: get dependencies
|
- name: get dependencies
|
||||||
run: pacman -Sy nodejs make gcc libcups --needed --noconfirm
|
run: pacman -Sy nodejs make gcc libcups nlohmann-json --needed --noconfirm
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make -j$(nproc)
|
run: make -j$(nproc)
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<img src="https://git.pupes.org/PoliEcho/ParaDocs/raw/branch/master/assets/logo.png" alt="logo of ParaDocs" width="196"></img>
|
<img src="https://git.pupes.org/PoliEcho/ParaDocs/raw/branch/master/assets/logo.png" alt="logo of ParaDocs" width="196"></img>
|
||||||
[](https://git.pupes.org/PoliEcho/ParaDocs/actions?workflow=build_test.yaml)
|
[](https://git.pupes.org/PoliEcho/ParaDocs/actions?workflow=build_test.yaml)
|
||||||
## Název:
|
# ParaDocs
|
||||||
ParaDocs
|
### joke criminal complaint generator with vi-motions
|
||||||
## Popis:
|
|
||||||
TUI text editor
|
|
||||||
## Prvky:
|
## dependencies
|
||||||
ANSI escape codes, Datové struktury a algoritmy
|
> ncurses
|
||||||
## Typ aplikace:
|
> nlohnnan-json
|
||||||
Konzolová aplikace
|
> g++
|
||||||
## Programovací jazyk:
|
|
||||||
C/C++
|
## compiletion
|
||||||
## Rozhraní:
|
```make -j$(nproc)```
|
||||||
text buffer, statusbar, commandline, vi-motions
|
|
||||||
+2
-2
@@ -3,7 +3,7 @@
|
|||||||
#ifndef NAME
|
#ifndef NAME
|
||||||
|
|
||||||
#define NAME "ParaDocs"
|
#define NAME "ParaDocs"
|
||||||
#define VERSION "0.0.1"
|
#define VERSION "1.0.0"
|
||||||
|
|
||||||
inline constexpr auto hash_djb2a(const std::string_view sv) {
|
inline constexpr auto hash_djb2a(const std::string_view sv) {
|
||||||
unsigned long hash{5381};
|
unsigned long hash{5381};
|
||||||
@@ -13,7 +13,7 @@ inline constexpr auto hash_djb2a(const std::string_view sv) {
|
|||||||
return hash;
|
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});
|
return hash_djb2a(std::string_view{str, len});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+82
-82
@@ -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 "gameske_funkce.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "strings.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 HEADER_COLOR_PAIR COLOR_RED
|
||||||
#define FIELD_NAME_COLOR_PAIR 10
|
#define FIELD_NAME_COLOR_PAIR 10
|
||||||
@@ -17,7 +17,7 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
|
|
||||||
[[nodiscard]] std::string vytvorTrestniOznameni() {
|
[[nodiscard]] std::string vytvorTrestniOznameni() {
|
||||||
current_allocated = &editor_easy_allocated;
|
current_allocated = &editor_easy_allocated;
|
||||||
auto trim = [](const char* str) -> std::string {
|
auto trim = [](const char *str) -> std::string {
|
||||||
std::string s(str);
|
std::string s(str);
|
||||||
if (s.empty())
|
if (s.empty())
|
||||||
return s;
|
return s;
|
||||||
@@ -40,26 +40,26 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
|
|
||||||
// Nastavení barev
|
// Nastavení barev
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(FIELD_NAME_COLOR_PAIR, COLOR_BLACK, COLOR_CYAN); // Popisky
|
init_pair(FIELD_NAME_COLOR_PAIR, COLOR_BLACK, COLOR_CYAN); // Popisky
|
||||||
init_pair(INPUT_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK); // Vstupní pole
|
init_pair(INPUT_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK); // Vstupní pole
|
||||||
|
|
||||||
// Hlavní okno s rámečkem
|
// 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);
|
box(main_win, 0, 0);
|
||||||
wrefresh(main_win);
|
wrefresh(main_win);
|
||||||
|
|
||||||
// Okno pro popisky
|
// 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));
|
wbkgd(label_win, COLOR_PAIR(FIELD_NAME_COLOR_PAIR));
|
||||||
|
|
||||||
// Okno pro vstupní pole
|
// 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));
|
wbkgd(field_win, COLOR_PAIR(INPUT_COLOR_PAIR));
|
||||||
keypad(field_win, TRUE);
|
keypad(field_win, TRUE);
|
||||||
|
|
||||||
// Definice polí
|
// Definice polí
|
||||||
struct FieldConfig {
|
struct FieldConfig {
|
||||||
const char* label;
|
const char *label;
|
||||||
int height;
|
int height;
|
||||||
int width;
|
int width;
|
||||||
bool multiline;
|
bool multiline;
|
||||||
@@ -84,18 +84,18 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
|
|
||||||
// Vykreslení popisků
|
// Vykreslení popisků
|
||||||
int label_row = 0;
|
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);
|
mvwprintw(label_win, label_row, 0, "%s", cfg.label);
|
||||||
label_row += cfg.height + 1;
|
label_row += cfg.height + 1;
|
||||||
}
|
}
|
||||||
wrefresh(label_win);
|
wrefresh(label_win);
|
||||||
|
|
||||||
// Vytvoření formuláře
|
// Vytvoření formuláře
|
||||||
std::vector<FIELD*> fields;
|
std::vector<FIELD *> fields;
|
||||||
int field_row = 0;
|
int field_row = 0;
|
||||||
|
|
||||||
for (const FieldConfig& cfg : field_configs) {
|
for (const FieldConfig &cfg : field_configs) {
|
||||||
FIELD* field = new_field(cfg.height, cfg.width, field_row, 0, 0, 0);
|
FIELD *field = new_field(cfg.height, cfg.width, field_row, 0, 0, 0);
|
||||||
set_field_back(field, A_UNDERLINE | COLOR_PAIR(INPUT_COLOR_PAIR));
|
set_field_back(field, A_UNDERLINE | COLOR_PAIR(INPUT_COLOR_PAIR));
|
||||||
field_opts_off(field, O_AUTOSKIP | O_STATIC);
|
field_opts_off(field, O_AUTOSKIP | O_STATIC);
|
||||||
|
|
||||||
@@ -109,9 +109,9 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
}
|
}
|
||||||
fields.push_back(nullptr);
|
fields.push_back(nullptr);
|
||||||
|
|
||||||
FORM* form = new_form(&fields[0]);
|
FORM *form = new_form(&fields[0]);
|
||||||
set_form_win(form, field_win);
|
set_form_win(form, field_win);
|
||||||
set_form_sub(form, derwin(field_win, LINES - 10, COLS - 40, 1, 1));
|
set_form_sub(form, derwin(field_win, LINES - 10, COLS - 40, 0, 1));
|
||||||
|
|
||||||
post_form(form);
|
post_form(form);
|
||||||
form_driver(form, REQ_FIRST_FIELD);
|
form_driver(form, REQ_FIRST_FIELD);
|
||||||
@@ -128,56 +128,56 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
bool exit_loop = false;
|
bool exit_loop = false;
|
||||||
while (!exit_loop && (ch = wgetch(field_win))) {
|
while (!exit_loop && (ch = wgetch(field_win))) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case KEY_F(10):
|
case KEY_F(10):
|
||||||
exit_loop = true;
|
exit_loop = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_DOWN:
|
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 {
|
||||||
form_driver(form, REQ_NEXT_FIELD);
|
form_driver(form, REQ_NEXT_FIELD);
|
||||||
form_driver(form, REQ_END_LINE);
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_UP:
|
case '\t':
|
||||||
form_driver(form, REQ_PREV_FIELD);
|
form_driver(form, REQ_NEXT_FIELD);
|
||||||
form_driver(form, REQ_END_LINE);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case KEY_LEFT:
|
case KEY_BTAB:
|
||||||
form_driver(form, REQ_PREV_CHAR);
|
form_driver(form, REQ_PREV_FIELD);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY_RIGHT:
|
default:
|
||||||
form_driver(form, REQ_NEXT_CHAR);
|
form_driver(form, ch);
|
||||||
break;
|
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
|
// Ruční aktualizace všech oken
|
||||||
@@ -197,7 +197,7 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
// Úklid
|
// Úklid
|
||||||
unpost_form(form);
|
unpost_form(form);
|
||||||
free_form(form);
|
free_form(form);
|
||||||
for (fieldnode*& f : fields)
|
for (fieldnode *&f : fields)
|
||||||
if (f)
|
if (f)
|
||||||
free_field(f);
|
free_field(f);
|
||||||
delwin(label_win);
|
delwin(label_win);
|
||||||
@@ -208,29 +208,29 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
|
|
||||||
// Aktuální datum
|
// Aktuální datum
|
||||||
std::time_t t = std::time(nullptr);
|
std::time_t t = std::time(nullptr);
|
||||||
std::tm* now = std::localtime(&t);
|
std::tm *now = std::localtime(&t);
|
||||||
char date_str[100];
|
char date_str[100];
|
||||||
std::strftime(date_str, sizeof(date_str), "%d.%m.%Y", now);
|
std::strftime(date_str, sizeof(date_str), "%d.%m.%Y", now);
|
||||||
|
|
||||||
auto comp_args =
|
auto comp_args =
|
||||||
std::make_format_args(field_values[0], // Jméno a příjmení odesílatele
|
std::make_format_args(field_values[0], // Jméno a příjmení odesílatele
|
||||||
field_values[1], // Adresa odesílatele
|
field_values[1], // Adresa odesílatele
|
||||||
field_values[2], // Telefon odesílatele
|
field_values[2], // Telefon odesílatele
|
||||||
field_values[3], // Email odesílatele
|
field_values[3], // Email odesílatele
|
||||||
|
|
||||||
field_values[4], // Jméno a příjmení adresáta
|
field_values[4], // Jméno a příjmení adresáta
|
||||||
field_values[5], // Adresa adresáta
|
field_values[5], // Adresa adresáta
|
||||||
field_values[6], // Telefon adresáta
|
field_values[6], // Telefon adresáta
|
||||||
field_values[7], // Email adresáta
|
field_values[7], // Email adresáta
|
||||||
|
|
||||||
date_str, // Aktuální datum
|
date_str, // Aktuální datum
|
||||||
field_values[8], // Místo činu
|
field_values[8], // Místo činu
|
||||||
field_values[9], // Datum činu
|
field_values[9], // Datum činu
|
||||||
|
|
||||||
field_values[10], // Popis činu
|
field_values[10], // Popis činu
|
||||||
field_values[11], // Důkazy
|
field_values[11], // Důkazy
|
||||||
field_values[12], // Další informace
|
field_values[12], // Další informace
|
||||||
field_values[0] // Jméno pro podpis
|
field_values[0] // Jméno pro podpis
|
||||||
);
|
);
|
||||||
|
|
||||||
std::string complaint =
|
std::string complaint =
|
||||||
|
|||||||
+119
-118
@@ -1,23 +1,23 @@
|
|||||||
#include <ncurses.h>
|
#include "strings.h"
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <ncurses.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "strings.h"
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
void save_document(std::string& text, std::vector<std::string>& lines) {
|
void save_document(std::string &text, std::vector<std::string> &lines) {
|
||||||
text = "";
|
text = "";
|
||||||
for (const std::string& line : lines) {
|
for (const std::string &line : lines) {
|
||||||
text.append(line);
|
text.append(line);
|
||||||
text.append("\n");
|
text.append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void editor_hard(std::string& text) {
|
void editor_hard(std::string &text) {
|
||||||
uint16_t cursor_x = 0;
|
uint16_t cursor_x = 0;
|
||||||
uint16_t cursor_y = 0;
|
uint16_t cursor_y = 0;
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
@@ -48,7 +48,8 @@ void editor_hard(std::string& text) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
clear();
|
clear();
|
||||||
// Draw text lines
|
// Draw text lines
|
||||||
for (size_t i = 0; i < window_height - 1 && i < lines.size(); i++) {
|
for (size_t i = 0;
|
||||||
|
i < static_cast<size_t>(window_height) - 1 && i < lines.size(); i++) {
|
||||||
mvprintw(i, 0, "%s", lines[i].c_str());
|
mvprintw(i, 0, "%s", lines[i].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,128 +62,128 @@ void editor_hard(std::string& text) {
|
|||||||
{
|
{
|
||||||
int ch = getch();
|
int ch = getch();
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'n': // Normal mode
|
case 'n': // Normal mode
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
if (cursor_x > 0) {
|
if (cursor_x > 0) {
|
||||||
cursor_x--;
|
cursor_x--;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'j':
|
|
||||||
if (cursor_y < lines.size() - 1) {
|
|
||||||
cursor_y++;
|
|
||||||
if (cursor_x > lines[cursor_y].length()) {
|
|
||||||
cursor_x = lines[cursor_y].length();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'k':
|
|
||||||
if (cursor_y > 0) {
|
|
||||||
cursor_y--;
|
|
||||||
if (cursor_x > lines[cursor_y].length()) {
|
|
||||||
cursor_x = lines[cursor_y].length();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
if (cursor_x < lines[cursor_y].length()) {
|
|
||||||
cursor_x++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
case 'a':
|
|
||||||
mode = 'i';
|
|
||||||
break;
|
|
||||||
case 'x':
|
|
||||||
if (cursor_x < lines[cursor_y].length()) {
|
|
||||||
lines[cursor_y].erase(cursor_x, 1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ':': {
|
|
||||||
// Enter command mode
|
|
||||||
std::string command = "";
|
|
||||||
int cmd_ch;
|
|
||||||
// Show command prompt
|
|
||||||
mvprintw(window_height - 1, 0, ":%s", command.c_str());
|
|
||||||
clrtoeol();
|
|
||||||
refresh();
|
|
||||||
|
|
||||||
while ((cmd_ch = getch()) != '\n' && cmd_ch != '\r') {
|
|
||||||
if (cmd_ch == 27) { // ESC - cancel command
|
|
||||||
break;
|
|
||||||
} else if (cmd_ch == KEY_BACKSPACE || cmd_ch == 127) {
|
|
||||||
if (!command.empty()) {
|
|
||||||
command.pop_back();
|
|
||||||
}
|
|
||||||
} else if (cmd_ch >= 32 && cmd_ch <= 126) {
|
|
||||||
command += static_cast<char>(cmd_ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
mvprintw(window_height - 1, 0, ":%s", command.c_str());
|
|
||||||
clrtoeol();
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute command
|
|
||||||
if (cmd_ch != 27) { // If not cancelled
|
|
||||||
switch (hash_djb2a(command)) {
|
|
||||||
case "q"_sh:
|
|
||||||
return;
|
|
||||||
break;
|
|
||||||
case "w"_sh:
|
|
||||||
save_document(text, lines);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "wq"_sh:
|
|
||||||
case "x"_sh:
|
|
||||||
save_document(text, lines);
|
|
||||||
return;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "q!"_sh:
|
|
||||||
return;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'j':
|
||||||
|
if (cursor_y < lines.size() - 1) {
|
||||||
|
cursor_y++;
|
||||||
|
if (cursor_x > lines[cursor_y].length()) {
|
||||||
|
cursor_x = lines[cursor_y].length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'k':
|
||||||
|
if (cursor_y > 0) {
|
||||||
|
cursor_y--;
|
||||||
|
if (cursor_x > lines[cursor_y].length()) {
|
||||||
|
cursor_x = lines[cursor_y].length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case 'i': // Insert mode
|
break;
|
||||||
switch (ch) {
|
case 'l':
|
||||||
case 27: // ESC
|
if (cursor_x < lines[cursor_y].length()) {
|
||||||
mode = 'n';
|
cursor_x++;
|
||||||
if (cursor_x > 0)
|
}
|
||||||
cursor_x--;
|
break;
|
||||||
|
case 'i':
|
||||||
|
case 'a':
|
||||||
|
mode = 'i';
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
if (cursor_x < lines[cursor_y].length()) {
|
||||||
|
lines[cursor_y].erase(cursor_x, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ':': {
|
||||||
|
// Enter command mode
|
||||||
|
std::string command = "";
|
||||||
|
int cmd_ch;
|
||||||
|
// Show command prompt
|
||||||
|
mvprintw(window_height - 1, 0, ":%s", command.c_str());
|
||||||
|
clrtoeol();
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
while ((cmd_ch = getch()) != '\n' && cmd_ch != '\r') {
|
||||||
|
if (cmd_ch == 27) { // ESC - cancel command
|
||||||
break;
|
break;
|
||||||
case KEY_BACKSPACE:
|
} else if (cmd_ch == KEY_BACKSPACE || cmd_ch == 127) {
|
||||||
case 127:
|
if (!command.empty()) {
|
||||||
if (mode == 'i' && cursor_x > 0) {
|
command.pop_back();
|
||||||
lines[cursor_y].erase(cursor_x - 1, 1);
|
|
||||||
cursor_x--;
|
|
||||||
}
|
}
|
||||||
|
} else if (cmd_ch >= 32 && cmd_ch <= 126) {
|
||||||
|
command += static_cast<char>(cmd_ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
mvprintw(window_height - 1, 0, ":%s", command.c_str());
|
||||||
|
clrtoeol();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute command
|
||||||
|
if (cmd_ch != 27) { // If not cancelled
|
||||||
|
switch (hash_djb2a(command)) {
|
||||||
|
case "q"_sh:
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case "w"_sh:
|
||||||
case '\r': {
|
save_document(text, lines);
|
||||||
// Insert new line
|
break;
|
||||||
std::string new_line = lines[cursor_y].substr(cursor_x);
|
|
||||||
lines[cursor_y] = lines[cursor_y].substr(0, cursor_x);
|
case "wq"_sh:
|
||||||
lines.insert(lines.begin() + cursor_y + 1, new_line);
|
case "x"_sh:
|
||||||
cursor_y++;
|
save_document(text, lines);
|
||||||
cursor_x = 0;
|
return;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "q!"_sh:
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
}
|
||||||
if (ch >= 32 && ch <= 126) {
|
} break;
|
||||||
if (mode == 'i') {
|
}
|
||||||
lines[cursor_y].insert(cursor_x, 1, ch);
|
break;
|
||||||
cursor_x++;
|
|
||||||
}
|
case 'i': // Insert mode
|
||||||
}
|
switch (ch) {
|
||||||
break;
|
case 27: // ESC
|
||||||
|
mode = 'n';
|
||||||
|
if (cursor_x > 0)
|
||||||
|
cursor_x--;
|
||||||
|
break;
|
||||||
|
case KEY_BACKSPACE:
|
||||||
|
case 127:
|
||||||
|
if (mode == 'i' && cursor_x > 0) {
|
||||||
|
lines[cursor_y].erase(cursor_x - 1, 1);
|
||||||
|
cursor_x--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case '\n':
|
||||||
|
case '\r': {
|
||||||
|
// Insert new line
|
||||||
|
std::string new_line = lines[cursor_y].substr(cursor_x);
|
||||||
|
lines[cursor_y] = lines[cursor_y].substr(0, cursor_x);
|
||||||
|
lines.insert(lines.begin() + cursor_y + 1, new_line);
|
||||||
|
cursor_y++;
|
||||||
|
cursor_x = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if (ch >= 32 && ch <= 126) {
|
||||||
|
if (mode == 'i') {
|
||||||
|
lines[cursor_y].insert(cursor_x, 1, ch);
|
||||||
|
cursor_x++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ void PrintHelp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PrintVersion() {
|
void PrintVersion() {
|
||||||
std::cout << NAME << loc_strings->version << ": " << VERSION << "\n";
|
std::cout << NAME << " " << loc_strings->version << ": " << VERSION << "\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+258
-243
@@ -1,19 +1,3 @@
|
|||||||
#include <curses.h>
|
|
||||||
#include <menu.h>
|
|
||||||
#include <ncurses.h>
|
|
||||||
#include <array>
|
|
||||||
#include <cerrno>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <filesystem>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "cups.h"
|
#include "cups.h"
|
||||||
@@ -24,13 +8,30 @@
|
|||||||
#include "signal.h"
|
#include "signal.h"
|
||||||
#include "strings.h"
|
#include "strings.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include <array>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <climits>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <curses.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <menu.h>
|
||||||
|
#include <ncurses.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
std::vector<allocation> main_menu_allocated;
|
std::vector<allocation> main_menu_allocated;
|
||||||
#define COMPLAINTS_DIR "complaints"
|
#define COMPLAINTS_DIR "complaints"
|
||||||
|
|
||||||
std::array<std::string, 2> get_name_date_from_item(ITEM* item) {
|
std::array<std::string, 2> get_name_date_from_item(ITEM *item) {
|
||||||
std::stringstream ss(item_description(item));
|
std::stringstream ss(item_description(item));
|
||||||
std::array<std::string, 2> name_date;
|
std::array<std::string, 2> name_date;
|
||||||
name_date[0] = item_name(item);
|
name_date[0] = item_name(item);
|
||||||
@@ -38,7 +39,7 @@ std::array<std::string, 2> get_name_date_from_item(ITEM* item) {
|
|||||||
return name_date;
|
return name_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reload_menu_from_directory(complete_menu& main_menu) {
|
void reload_menu_from_directory(complete_menu &main_menu) {
|
||||||
// Clean up existing menu items and allocated memory
|
// Clean up existing menu items and allocated memory
|
||||||
if (main_menu.menu != nullptr) {
|
if (main_menu.menu != nullptr) {
|
||||||
unpost_menu(main_menu.menu);
|
unpost_menu(main_menu.menu);
|
||||||
@@ -61,7 +62,7 @@ void reload_menu_from_directory(complete_menu& main_menu) {
|
|||||||
for (auto it = main_menu_allocated.begin();
|
for (auto it = main_menu_allocated.begin();
|
||||||
it != main_menu_allocated.end();) {
|
it != main_menu_allocated.end();) {
|
||||||
if (it->type == GENERIC_TYPE) {
|
if (it->type == GENERIC_TYPE) {
|
||||||
delete[] static_cast<char*>(it->ptr);
|
delete[] static_cast<char *>(it->ptr);
|
||||||
it = main_menu_allocated.erase(it);
|
it = main_menu_allocated.erase(it);
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
@@ -69,10 +70,10 @@ void reload_menu_from_directory(complete_menu& main_menu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recreate items from directory (same logic as initialization)
|
// Recreate items from directory (same logic as initialization)
|
||||||
std::vector<ITEM*> items;
|
std::vector<ITEM *> items;
|
||||||
|
|
||||||
if (std::filesystem::exists(COMPLAINTS_DIR)) {
|
if (std::filesystem::exists(COMPLAINTS_DIR)) {
|
||||||
for (const std::filesystem::directory_entry& directroy_entry :
|
for (const std::filesystem::directory_entry &directroy_entry :
|
||||||
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
|
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
|
||||||
if (directroy_entry.is_regular_file()) {
|
if (directroy_entry.is_regular_file()) {
|
||||||
std::ifstream file(directroy_entry.path());
|
std::ifstream file(directroy_entry.path());
|
||||||
@@ -82,23 +83,28 @@ void reload_menu_from_directory(complete_menu& main_menu) {
|
|||||||
for (uint8_t i = 0; i < ARRAY_SIZE(name_date); i++) {
|
for (uint8_t i = 0; i < ARRAY_SIZE(name_date); i++) {
|
||||||
std::getline(ssfn, name_date[i], '_');
|
std::getline(ssfn, name_date[i], '_');
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
json complaint_json = json::parse(file);
|
||||||
|
|
||||||
json complaint_json = json::parse(file);
|
if (complaint_json["status"].is_null() ||
|
||||||
if (complaint_json["status"].is_null() ||
|
complaint_json["status"].get<uint8_t>() >= STATUS_COUNT) {
|
||||||
complaint_json["status"].get<uint8_t>() >= STATUS_COUNT) {
|
std::cerr << "Invalid status in file: "
|
||||||
std::cerr << "Invalid status in file: "
|
<< directroy_entry.path().filename().string()
|
||||||
<< directroy_entry.path().filename().string() << std::endl;
|
<< std::endl;
|
||||||
safe_exit(EINVAL);
|
safe_exit(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
name_date[1].append(" ");
|
||||||
|
name_date[1].append(
|
||||||
|
loc_strings
|
||||||
|
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
||||||
|
} catch (...) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
name_date[1].append(" ");
|
char *name = new char[name_date[0].length() + 1];
|
||||||
name_date[1].append(
|
|
||||||
loc_strings
|
|
||||||
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
|
||||||
|
|
||||||
char* name = new char[name_date[0].length() + 1];
|
|
||||||
main_menu_allocated.push_back({GENERIC_TYPE, name, 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});
|
main_menu_allocated.push_back({GENERIC_TYPE, date, 1});
|
||||||
|
|
||||||
strcpy(name, name_date[0].c_str());
|
strcpy(name, name_date[0].c_str());
|
||||||
@@ -112,9 +118,9 @@ void reload_menu_from_directory(complete_menu& main_menu) {
|
|||||||
items.push_back(nullptr);
|
items.push_back(nullptr);
|
||||||
|
|
||||||
// Create new menu items array
|
// Create new menu items array
|
||||||
main_menu.items = new ITEM*[items.size()];
|
main_menu.items = new ITEM *[items.size()];
|
||||||
main_menu.items_size = items.size() - 1;
|
main_menu.items_size = items.size() - 1;
|
||||||
memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM*)));
|
memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM *)));
|
||||||
|
|
||||||
// Create new menu
|
// Create new menu
|
||||||
main_menu.menu = new_menu(main_menu.items);
|
main_menu.menu = new_menu(main_menu.items);
|
||||||
@@ -138,7 +144,7 @@ void menu() {
|
|||||||
start_color();
|
start_color();
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
curs_set(0); // Makes cursor invisible
|
curs_set(0); // Makes cursor invisible
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
init_pair(i, i, COLOR_BLACK);
|
init_pair(i, i, COLOR_BLACK);
|
||||||
@@ -149,9 +155,9 @@ void menu() {
|
|||||||
complete_menu main_menu = {nullptr, nullptr, 0, nullptr};
|
complete_menu main_menu = {nullptr, nullptr, 0, nullptr};
|
||||||
main_menu_allocated.push_back({COMPLETE_MENU_TYPE, &main_menu, 1});
|
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)) {
|
if (std::filesystem::exists(COMPLAINTS_DIR)) {
|
||||||
for (const std::filesystem::directory_entry& directroy_entry :
|
for (const std::filesystem::directory_entry &directroy_entry :
|
||||||
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
|
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
|
||||||
if (directroy_entry.is_regular_file()) {
|
if (directroy_entry.is_regular_file()) {
|
||||||
std::ifstream file(directroy_entry.path());
|
std::ifstream file(directroy_entry.path());
|
||||||
@@ -160,22 +166,26 @@ void menu() {
|
|||||||
for (uint8_t i = 0; i < ARRAY_SIZE(name_date); i++) {
|
for (uint8_t i = 0; i < ARRAY_SIZE(name_date); i++) {
|
||||||
std::getline(ssfn, name_date[i], '_');
|
std::getline(ssfn, name_date[i], '_');
|
||||||
}
|
}
|
||||||
json complaint_json = json::parse(file);
|
try {
|
||||||
if (complaint_json["status"].is_null() ||
|
json complaint_json = json::parse(file);
|
||||||
complaint_json["status"].get<size_t>() >= STATUS_COUNT) {
|
if (complaint_json["status"].is_null() ||
|
||||||
std::cerr << "Invalid status in file: "
|
complaint_json["status"].get<size_t>() >= STATUS_COUNT) {
|
||||||
<< directroy_entry.path().filename().string()
|
std::cerr << "Invalid status in file: "
|
||||||
<< std::endl;
|
<< directroy_entry.path().filename().string()
|
||||||
safe_exit(EINVAL);
|
<< std::endl;
|
||||||
|
safe_exit(EINVAL);
|
||||||
|
}
|
||||||
|
name_date[1].append(" ");
|
||||||
|
name_date[1].append(
|
||||||
|
loc_strings
|
||||||
|
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
||||||
|
} catch (...) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
name_date[1].append(" ");
|
|
||||||
name_date[1].append(
|
|
||||||
loc_strings
|
|
||||||
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
|
||||||
|
|
||||||
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});
|
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});
|
main_menu_allocated.push_back({GENERIC_TYPE, date, 1});
|
||||||
strcpy(name, name_date[0].c_str());
|
strcpy(name, name_date[0].c_str());
|
||||||
strcpy(date, name_date[1].c_str());
|
strcpy(date, name_date[1].c_str());
|
||||||
@@ -186,9 +196,9 @@ void menu() {
|
|||||||
std::filesystem::create_directory(COMPLAINTS_DIR);
|
std::filesystem::create_directory(COMPLAINTS_DIR);
|
||||||
}
|
}
|
||||||
items.push_back(nullptr);
|
items.push_back(nullptr);
|
||||||
main_menu.items = new ITEM*[items.size()];
|
main_menu.items = new ITEM *[items.size()];
|
||||||
main_menu.items_size = items.size() - 1;
|
main_menu.items_size = items.size() - 1;
|
||||||
memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM*)));
|
memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Crate menu */
|
/* Crate menu */
|
||||||
@@ -222,204 +232,209 @@ void menu() {
|
|||||||
int c;
|
int c;
|
||||||
while ((c = wgetch(main_menu.win)) != KEY_F(1)) {
|
while ((c = wgetch(main_menu.win)) != KEY_F(1)) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
menu_driver(main_menu.menu, REQ_DOWN_ITEM);
|
menu_driver(main_menu.menu, REQ_DOWN_ITEM);
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
menu_driver(main_menu.menu, REQ_UP_ITEM);
|
menu_driver(main_menu.menu, REQ_UP_ITEM);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
break;
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
switch (hash_djb2a(spawncmd())) {
|
switch (hash_djb2a(spawncmd())) {
|
||||||
case "print"_sh:
|
case "print"_sh:
|
||||||
case "p"_sh: {
|
case "p"_sh: {
|
||||||
// DONT FORGET TO PRINT ACTUAL DOCUMENT
|
// DONT FORGET TO PRINT ACTUAL DOCUMENT
|
||||||
std::array<std::string, 2> name_date =
|
|
||||||
get_name_date_from_item(current_item(main_menu.menu));
|
|
||||||
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] +
|
|
||||||
'_' + name_date[1]);
|
|
||||||
if (!selected_file.is_open()) {
|
|
||||||
std::clog << selected_file.rdstate() << "\n";
|
|
||||||
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
|
||||||
<< "\n"
|
|
||||||
<< "File: "
|
|
||||||
<< COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
|
||||||
name_date[1]
|
|
||||||
<< "\n";
|
|
||||||
exit(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
json selected_file_json = json::parse(selected_file);
|
|
||||||
|
|
||||||
printDocument(
|
|
||||||
selected_file_json["complaint_text"].get<std::string>());
|
|
||||||
current_allocated = &main_menu_allocated;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "easy_edit"_sh:
|
|
||||||
case "ee"_sh: {
|
|
||||||
const std::string name = spawncmd(loc_strings->reference_name);
|
|
||||||
if (name == "") {
|
|
||||||
print_in_middle(main_menu.win, 10, 0, 40,
|
|
||||||
loc_strings->invalid_input, COLOR_PAIR(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
const time_t current_time = time(nullptr);
|
|
||||||
const tm* local_time = localtime(¤t_time);
|
|
||||||
|
|
||||||
char formatted_date[11];
|
|
||||||
strftime(formatted_date, sizeof(formatted_date), "%d-%m-%Y",
|
|
||||||
local_time);
|
|
||||||
|
|
||||||
std::ofstream complaint_file(COMPLAINTS_DIR "/" + name + "_" +
|
|
||||||
formatted_date);
|
|
||||||
|
|
||||||
const std::string complaint_text = vytvorTrestniOznameni();
|
|
||||||
|
|
||||||
json complaint_json = {{"date", formatted_date},
|
|
||||||
{"status", NOT_SEND},
|
|
||||||
{"complaint_text", complaint_text}};
|
|
||||||
|
|
||||||
complaint_file << complaint_json;
|
|
||||||
complaint_file.close();
|
|
||||||
current_allocated = &main_menu_allocated;
|
|
||||||
reload_menu_from_directory(main_menu);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "eh"_sh: {
|
|
||||||
std::array<std::string, 2> name_date =
|
|
||||||
get_name_date_from_item(current_item(main_menu.menu));
|
|
||||||
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] +
|
|
||||||
'_' + name_date[1]);
|
|
||||||
if (!selected_file.is_open()) {
|
|
||||||
std::clog << selected_file.rdstate() << "\n";
|
|
||||||
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
|
||||||
<< "\n"
|
|
||||||
<< "File: "
|
|
||||||
<< COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
|
||||||
name_date[1]
|
|
||||||
<< "\n";
|
|
||||||
exit(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
json selected_file_json = json::parse(selected_file);
|
|
||||||
selected_file.close();
|
|
||||||
std::string complaint_text =
|
|
||||||
selected_file_json["complaint_text"].get<std::string>();
|
|
||||||
editor_hard(complaint_text);
|
|
||||||
curs_set(0);
|
|
||||||
clear();
|
|
||||||
selected_file_json["complaint_text"] = complaint_text;
|
|
||||||
std::ofstream selected_file_out(COMPLAINTS_DIR "/" + name_date[0] +
|
|
||||||
'_' + name_date[1]);
|
|
||||||
selected_file_out << selected_file_json;
|
|
||||||
selected_file_out.close();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
print_in_middle(main_menu.win, 10, 0, 40,
|
|
||||||
loc_strings->unknown_command, COLOR_PAIR(1));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'm': {
|
|
||||||
int current_item_index = item_index(current_item(main_menu.menu));
|
|
||||||
std::array<std::string, 2> name_date =
|
std::array<std::string, 2> name_date =
|
||||||
get_name_date_from_item(current_item(main_menu.menu));
|
get_name_date_from_item(current_item(main_menu.menu));
|
||||||
|
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
||||||
{
|
name_date[1]);
|
||||||
uint8_t n = 0;
|
if (!selected_file.is_open()) {
|
||||||
size_t indexes[2];
|
std::clog << selected_file.rdstate() << "\n";
|
||||||
for (size_t i = 0; (i < main_menu_allocated.size()); i++) {
|
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
||||||
if (main_menu_allocated[i].ptr ==
|
<< "\n"
|
||||||
item_name(current_item(main_menu.menu))) {
|
<< "File: "
|
||||||
delete[] static_cast<char*>(main_menu_allocated[i].ptr);
|
<< COMPLAINTS_DIR "/" + name_date[0] + '_' + name_date[1]
|
||||||
indexes[0] = i;
|
<< "\n";
|
||||||
n++;
|
exit(EINVAL);
|
||||||
} else if (main_menu_allocated[i].ptr ==
|
|
||||||
item_description(current_item(main_menu.menu))) {
|
|
||||||
delete[] static_cast<char*>(main_menu_allocated[i].ptr);
|
|
||||||
indexes[1] = i;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
if (n >= 2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (indexes[0] > indexes[1]) {
|
|
||||||
std::swap(indexes[0], indexes[1]);
|
|
||||||
}
|
|
||||||
main_menu_allocated.erase(main_menu_allocated.begin() + indexes[1]);
|
|
||||||
main_menu_allocated.erase(main_menu_allocated.begin() + indexes[0]);
|
|
||||||
}
|
}
|
||||||
{
|
try {
|
||||||
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
|
||||||
name_date[1]);
|
|
||||||
if (!selected_file.is_open()) {
|
|
||||||
std::clog << selected_file.rdstate() << "\n";
|
|
||||||
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
|
||||||
<< "\n"
|
|
||||||
<< "File: "
|
|
||||||
<< COMPLAINTS_DIR "/" + name_date[0] + '_' + name_date[1]
|
|
||||||
<< "\n";
|
|
||||||
exit(EINVAL);
|
|
||||||
}
|
|
||||||
json selected_file_json = json::parse(selected_file);
|
json selected_file_json = json::parse(selected_file);
|
||||||
selected_file.close();
|
|
||||||
if (selected_file_json["status"].is_null() ||
|
|
||||||
selected_file_json["status"].get<size_t>() < STATUS_COUNT) {
|
|
||||||
|
|
||||||
(selected_file_json["status"].get<uint8_t>() + 1 >= STATUS_COUNT)
|
printDocument(
|
||||||
? selected_file_json["status"] = NOT_SEND
|
selected_file_json["complaint_text"].get<std::string>());
|
||||||
: selected_file_json["status"] =
|
current_allocated = &main_menu_allocated;
|
||||||
selected_file_json["status"].get<uint8_t>() + 1;
|
} catch (...) {
|
||||||
|
safe_exit(EINVAL);
|
||||||
std::ofstream selected_file(COMPLAINTS_DIR "/" + name_date[0] +
|
|
||||||
'_' + name_date[1]);
|
|
||||||
selected_file << selected_file_json;
|
|
||||||
selected_file.close();
|
|
||||||
} else {
|
|
||||||
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
|
||||||
<< "\n";
|
|
||||||
exit(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
name_date[1].append(" ");
|
|
||||||
name_date[1].append(
|
|
||||||
loc_strings->status_strings[selected_file_json["status"]
|
|
||||||
.get<uint8_t>()]);
|
|
||||||
char* date_status = new char[name_date[1].length() + 1];
|
|
||||||
main_menu_allocated.push_back({GENERIC_TYPE, date_status, 1});
|
|
||||||
strlcpy(date_status, name_date[1].c_str(), name_date[1].length() + 1);
|
|
||||||
|
|
||||||
char* name = new char[name_date[0].length() + 1];
|
|
||||||
main_menu_allocated.push_back({GENERIC_TYPE, name, 1});
|
|
||||||
strlcpy(name, name_date[0].c_str(), name_date[0].length() + 1);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < main_menu.items_size; i++) {
|
|
||||||
if (main_menu.items[i] == current_item(main_menu.menu)) {
|
|
||||||
free_item(main_menu.items[i]);
|
|
||||||
main_menu.items[i] = new_item(name, date_status);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
WINDOW* old_win_sub = menu_sub(main_menu.menu);
|
|
||||||
unpost_menu(main_menu.menu);
|
|
||||||
free_menu(main_menu.menu);
|
|
||||||
main_menu.menu = new_menu(main_menu.items);
|
|
||||||
set_menu_win(main_menu.menu, main_menu.win);
|
|
||||||
set_menu_sub(main_menu.menu, old_win_sub);
|
|
||||||
set_menu_format(main_menu.menu, 7, 1);
|
|
||||||
set_menu_mark(main_menu.menu, " * ");
|
|
||||||
set_current_item(main_menu.menu, main_menu.items[current_item_index]);
|
|
||||||
post_menu(main_menu.menu);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "easy_edit"_sh:
|
||||||
|
case "ee"_sh: {
|
||||||
|
const std::string name = spawncmd(loc_strings->reference_name);
|
||||||
|
if (name == "") {
|
||||||
|
print_in_middle(main_menu.win, 10, 0, 40, loc_strings->invalid_input,
|
||||||
|
COLOR_PAIR(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
const time_t current_time = time(nullptr);
|
||||||
|
const tm *local_time = localtime(¤t_time);
|
||||||
|
|
||||||
|
char formatted_date[11];
|
||||||
|
strftime(formatted_date, sizeof(formatted_date), "%d-%m-%Y",
|
||||||
|
local_time);
|
||||||
|
|
||||||
|
std::ofstream complaint_file(COMPLAINTS_DIR "/" + name + "_" +
|
||||||
|
formatted_date);
|
||||||
|
|
||||||
|
const std::string complaint_text = vytvorTrestniOznameni();
|
||||||
|
|
||||||
|
json complaint_json = {{"date", formatted_date},
|
||||||
|
{"status", NOT_SEND},
|
||||||
|
{"complaint_text", complaint_text}};
|
||||||
|
|
||||||
|
complaint_file << complaint_json;
|
||||||
|
complaint_file.close();
|
||||||
|
current_allocated = &main_menu_allocated;
|
||||||
|
reload_menu_from_directory(main_menu);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "eh"_sh: {
|
||||||
|
std::array<std::string, 2> name_date =
|
||||||
|
get_name_date_from_item(current_item(main_menu.menu));
|
||||||
|
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
||||||
|
name_date[1]);
|
||||||
|
if (!selected_file.is_open()) {
|
||||||
|
std::clog << selected_file.rdstate() << "\n";
|
||||||
|
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
||||||
|
<< "\n"
|
||||||
|
<< "File: "
|
||||||
|
<< COMPLAINTS_DIR "/" + name_date[0] + '_' + name_date[1]
|
||||||
|
<< "\n";
|
||||||
|
exit(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
json selected_file_json = json::parse(selected_file);
|
||||||
|
selected_file.close();
|
||||||
|
std::string complaint_text =
|
||||||
|
selected_file_json["complaint_text"].get<std::string>();
|
||||||
|
editor_hard(complaint_text);
|
||||||
|
curs_set(0);
|
||||||
|
clear();
|
||||||
|
selected_file_json["complaint_text"] = complaint_text;
|
||||||
|
std::ofstream selected_file_out(COMPLAINTS_DIR "/" + name_date[0] +
|
||||||
|
'_' + name_date[1]);
|
||||||
|
selected_file_out << selected_file_json;
|
||||||
|
selected_file_out.close();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
print_in_middle(main_menu.win, 10, 0, 40, loc_strings->unknown_command,
|
||||||
|
COLOR_PAIR(1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'm': {
|
||||||
|
int current_item_index = item_index(current_item(main_menu.menu));
|
||||||
|
std::array<std::string, 2> name_date =
|
||||||
|
get_name_date_from_item(current_item(main_menu.menu));
|
||||||
|
|
||||||
|
{
|
||||||
|
uint8_t n = 0;
|
||||||
|
size_t indexes[2] = {ULONG_MAX, ULONG_MAX}; // fix compiler warning
|
||||||
|
for (size_t i = 0; (i < main_menu_allocated.size()); i++) {
|
||||||
|
if (main_menu_allocated[i].ptr ==
|
||||||
|
item_name(current_item(main_menu.menu))) {
|
||||||
|
delete[] static_cast<char *>(main_menu_allocated[i].ptr);
|
||||||
|
indexes[0] = i;
|
||||||
|
n++;
|
||||||
|
} else if (main_menu_allocated[i].ptr ==
|
||||||
|
item_description(current_item(main_menu.menu))) {
|
||||||
|
delete[] static_cast<char *>(main_menu_allocated[i].ptr);
|
||||||
|
indexes[1] = i;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
if (n >= 2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (indexes[0] == ULONG_MAX || indexes[1] == ULONG_MAX) {
|
||||||
|
std::cerr << RED "[ERROR]" << RESET " HOW DID THIS EVEN HAPPEN\n";
|
||||||
|
safe_exit(84);
|
||||||
|
}
|
||||||
|
if (indexes[0] > indexes[1]) {
|
||||||
|
std::swap(indexes[0], indexes[1]);
|
||||||
|
}
|
||||||
|
main_menu_allocated.erase(main_menu_allocated.begin() + indexes[1]);
|
||||||
|
main_menu_allocated.erase(main_menu_allocated.begin() + indexes[0]);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
||||||
|
name_date[1]);
|
||||||
|
if (!selected_file.is_open()) {
|
||||||
|
std::clog << selected_file.rdstate() << "\n";
|
||||||
|
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
||||||
|
<< "\n"
|
||||||
|
<< "File: "
|
||||||
|
<< COMPLAINTS_DIR "/" + name_date[0] + '_' + name_date[1]
|
||||||
|
<< "\n";
|
||||||
|
exit(EINVAL);
|
||||||
|
}
|
||||||
|
json selected_file_json = json::parse(selected_file);
|
||||||
|
selected_file.close();
|
||||||
|
if (selected_file_json["status"].is_null() ||
|
||||||
|
selected_file_json["status"].get<size_t>() < STATUS_COUNT) {
|
||||||
|
|
||||||
|
(selected_file_json["status"].get<uint8_t>() + 1 >= STATUS_COUNT)
|
||||||
|
? selected_file_json["status"] = NOT_SEND
|
||||||
|
: selected_file_json["status"] =
|
||||||
|
selected_file_json["status"].get<uint8_t>() + 1;
|
||||||
|
|
||||||
|
std::ofstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
||||||
|
name_date[1]);
|
||||||
|
selected_file << selected_file_json;
|
||||||
|
selected_file.close();
|
||||||
|
} else {
|
||||||
|
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
||||||
|
<< "\n";
|
||||||
|
exit(EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
name_date[1].append(" ");
|
||||||
|
name_date[1].append(
|
||||||
|
loc_strings
|
||||||
|
->status_strings[selected_file_json["status"].get<uint8_t>()]);
|
||||||
|
char *date_status = new char[name_date[1].length() + 1];
|
||||||
|
main_menu_allocated.push_back({GENERIC_TYPE, date_status, 1});
|
||||||
|
strlcpy(date_status, name_date[1].c_str(), name_date[1].length() + 1);
|
||||||
|
|
||||||
|
char *name = new char[name_date[0].length() + 1];
|
||||||
|
main_menu_allocated.push_back({GENERIC_TYPE, name, 1});
|
||||||
|
strlcpy(name, name_date[0].c_str(), name_date[0].length() + 1);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < main_menu.items_size; i++) {
|
||||||
|
if (main_menu.items[i] == current_item(main_menu.menu)) {
|
||||||
|
free_item(main_menu.items[i]);
|
||||||
|
main_menu.items[i] = new_item(name, date_status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WINDOW *old_win_sub = menu_sub(main_menu.menu);
|
||||||
|
unpost_menu(main_menu.menu);
|
||||||
|
free_menu(main_menu.menu);
|
||||||
|
main_menu.menu = new_menu(main_menu.items);
|
||||||
|
set_menu_win(main_menu.menu, main_menu.win);
|
||||||
|
set_menu_sub(main_menu.menu, old_win_sub);
|
||||||
|
set_menu_format(main_menu.menu, 7, 1);
|
||||||
|
set_menu_mark(main_menu.menu, " * ");
|
||||||
|
set_current_item(main_menu.menu, main_menu.items[current_item_index]);
|
||||||
|
post_menu(main_menu.menu);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wrefresh(main_menu.win);
|
wrefresh(main_menu.win);
|
||||||
refresh();
|
refresh();
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@ constexpr strings english_strings{
|
|||||||
.print_this_help = "Print this help",
|
.print_this_help = "Print this help",
|
||||||
.print_version = "Print version",
|
.print_version = "Print version",
|
||||||
.version = "version",
|
.version = "version",
|
||||||
.main_menu = "Main menu",
|
.main_menu = "List of complaints",
|
||||||
.f1_to_exit = "F1 to exit",
|
.f1_to_exit = "F1 to exit",
|
||||||
.unknown_command = "Unknown command:",
|
.unknown_command = "Unknown command:",
|
||||||
.min_terminal_size = "Minimum terminal size: 90x28",
|
.min_terminal_size = "Minimum terminal size: 90x28",
|
||||||
@@ -88,7 +88,7 @@ constexpr strings czech_strings{
|
|||||||
.print_this_help = "Zobrazit tuto nápovědu",
|
.print_this_help = "Zobrazit tuto nápovědu",
|
||||||
.print_version = "Zobrazit verzi",
|
.print_version = "Zobrazit verzi",
|
||||||
.version = "verze",
|
.version = "verze",
|
||||||
.main_menu = "Hlavní nabídka",
|
.main_menu = "Seznam Oznámení",
|
||||||
.f1_to_exit = "F1 pro ukončení",
|
.f1_to_exit = "F1 pro ukončení",
|
||||||
.unknown_command = "Neznámý příkaz: ",
|
.unknown_command = "Neznámý příkaz: ",
|
||||||
.min_terminal_size = "Minimální velikost terminálu: 90x28",
|
.min_terminal_size = "Minimální velikost terminálu: 90x28",
|
||||||
@@ -158,4 +158,4 @@ Podpis oznamovatele: {0}
|
|||||||
.reference_name = "Referenční Název",
|
.reference_name = "Referenční Název",
|
||||||
.status_strings = {"Nebylo odesláno", "Odesláno", "Zamítnuto", "Přijato"}};
|
.status_strings = {"Nebylo odesláno", "Odesláno", "Zamítnuto", "Přijato"}};
|
||||||
|
|
||||||
const strings* loc_strings;
|
const strings *loc_strings;
|
||||||
Reference in New Issue
Block a user