Compare commits
6 Commits
bf02560cdd
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e4784cfaa | |||
| e6961d6d6d | |||
| 00f261696f | |||
| d330878f8a | |||
| 30c8ad2ca7 | |||
| edd21acaa5 |
@@ -6,7 +6,7 @@ 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
|
||||||
|
|||||||
@@ -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
|
|
||||||
+1
-1
@@ -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};
|
||||||
|
|||||||
+8
-8
@@ -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
|
||||||
@@ -111,7 +111,7 @@ std::vector<allocation> editor_easy_allocated;
|
|||||||
|
|
||||||
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);
|
||||||
|
|||||||
+4
-3
@@ -1,12 +1,12 @@
|
|||||||
#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) {
|
||||||
@@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+51
-36
@@ -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,6 +8,23 @@
|
|||||||
#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;
|
||||||
|
|
||||||
@@ -82,12 +83,14 @@ 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() << std::endl;
|
<< directroy_entry.path().filename().string()
|
||||||
|
<< std::endl;
|
||||||
safe_exit(EINVAL);
|
safe_exit(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +98,9 @@ void reload_menu_from_directory(complete_menu& main_menu) {
|
|||||||
name_date[1].append(
|
name_date[1].append(
|
||||||
loc_strings
|
loc_strings
|
||||||
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
||||||
|
} catch (...) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
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});
|
||||||
@@ -160,6 +166,7 @@ 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], '_');
|
||||||
}
|
}
|
||||||
|
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<size_t>() >= STATUS_COUNT) {
|
complaint_json["status"].get<size_t>() >= STATUS_COUNT) {
|
||||||
@@ -172,6 +179,9 @@ void menu() {
|
|||||||
name_date[1].append(
|
name_date[1].append(
|
||||||
loc_strings
|
loc_strings
|
||||||
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
||||||
|
} catch (...) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
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});
|
||||||
@@ -239,32 +249,34 @@ void menu() {
|
|||||||
// DONT FORGET TO PRINT ACTUAL DOCUMENT
|
// DONT FORGET TO PRINT ACTUAL DOCUMENT
|
||||||
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] +
|
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
||||||
'_' + name_date[1]);
|
name_date[1]);
|
||||||
if (!selected_file.is_open()) {
|
if (!selected_file.is_open()) {
|
||||||
std::clog << selected_file.rdstate() << "\n";
|
std::clog << selected_file.rdstate() << "\n";
|
||||||
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "File: "
|
<< "File: "
|
||||||
<< COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
<< COMPLAINTS_DIR "/" + name_date[0] + '_' + name_date[1]
|
||||||
name_date[1]
|
|
||||||
<< "\n";
|
<< "\n";
|
||||||
exit(EINVAL);
|
exit(EINVAL);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
json selected_file_json = json::parse(selected_file);
|
json selected_file_json = json::parse(selected_file);
|
||||||
|
|
||||||
printDocument(
|
printDocument(
|
||||||
selected_file_json["complaint_text"].get<std::string>());
|
selected_file_json["complaint_text"].get<std::string>());
|
||||||
current_allocated = &main_menu_allocated;
|
current_allocated = &main_menu_allocated;
|
||||||
|
} catch (...) {
|
||||||
|
safe_exit(EINVAL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "easy_edit"_sh:
|
case "easy_edit"_sh:
|
||||||
case "ee"_sh: {
|
case "ee"_sh: {
|
||||||
const std::string name = spawncmd(loc_strings->reference_name);
|
const std::string name = spawncmd(loc_strings->reference_name);
|
||||||
if (name == "") {
|
if (name == "") {
|
||||||
print_in_middle(main_menu.win, 10, 0, 40,
|
print_in_middle(main_menu.win, 10, 0, 40, loc_strings->invalid_input,
|
||||||
loc_strings->invalid_input, COLOR_PAIR(1));
|
COLOR_PAIR(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
const time_t current_time = time(nullptr);
|
const time_t current_time = time(nullptr);
|
||||||
@@ -292,15 +304,14 @@ void menu() {
|
|||||||
case "eh"_sh: {
|
case "eh"_sh: {
|
||||||
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] +
|
std::ifstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
||||||
'_' + name_date[1]);
|
name_date[1]);
|
||||||
if (!selected_file.is_open()) {
|
if (!selected_file.is_open()) {
|
||||||
std::clog << selected_file.rdstate() << "\n";
|
std::clog << selected_file.rdstate() << "\n";
|
||||||
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
std::cerr << RED "[ERROR] " RESET << loc_strings->invalid_input
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< "File: "
|
<< "File: "
|
||||||
<< COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
<< COMPLAINTS_DIR "/" + name_date[0] + '_' + name_date[1]
|
||||||
name_date[1]
|
|
||||||
<< "\n";
|
<< "\n";
|
||||||
exit(EINVAL);
|
exit(EINVAL);
|
||||||
}
|
}
|
||||||
@@ -321,8 +332,8 @@ void menu() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
print_in_middle(main_menu.win, 10, 0, 40,
|
print_in_middle(main_menu.win, 10, 0, 40, loc_strings->unknown_command,
|
||||||
loc_strings->unknown_command, COLOR_PAIR(1));
|
COLOR_PAIR(1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -333,7 +344,7 @@ void menu() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
uint8_t n = 0;
|
uint8_t n = 0;
|
||||||
size_t indexes[2];
|
size_t indexes[2] = {ULONG_MAX, ULONG_MAX}; // fix compiler warning
|
||||||
for (size_t i = 0; (i < main_menu_allocated.size()); i++) {
|
for (size_t i = 0; (i < main_menu_allocated.size()); i++) {
|
||||||
if (main_menu_allocated[i].ptr ==
|
if (main_menu_allocated[i].ptr ==
|
||||||
item_name(current_item(main_menu.menu))) {
|
item_name(current_item(main_menu.menu))) {
|
||||||
@@ -350,6 +361,10 @@ void menu() {
|
|||||||
break;
|
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]) {
|
if (indexes[0] > indexes[1]) {
|
||||||
std::swap(indexes[0], indexes[1]);
|
std::swap(indexes[0], indexes[1]);
|
||||||
}
|
}
|
||||||
@@ -378,8 +393,8 @@ void menu() {
|
|||||||
: selected_file_json["status"] =
|
: selected_file_json["status"] =
|
||||||
selected_file_json["status"].get<uint8_t>() + 1;
|
selected_file_json["status"].get<uint8_t>() + 1;
|
||||||
|
|
||||||
std::ofstream selected_file(COMPLAINTS_DIR "/" + name_date[0] +
|
std::ofstream selected_file(COMPLAINTS_DIR "/" + name_date[0] + '_' +
|
||||||
'_' + name_date[1]);
|
name_date[1]);
|
||||||
selected_file << selected_file_json;
|
selected_file << selected_file_json;
|
||||||
selected_file.close();
|
selected_file.close();
|
||||||
} else {
|
} else {
|
||||||
@@ -390,8 +405,8 @@ void menu() {
|
|||||||
|
|
||||||
name_date[1].append(" ");
|
name_date[1].append(" ");
|
||||||
name_date[1].append(
|
name_date[1].append(
|
||||||
loc_strings->status_strings[selected_file_json["status"]
|
loc_strings
|
||||||
.get<uint8_t>()]);
|
->status_strings[selected_file_json["status"].get<uint8_t>()]);
|
||||||
char *date_status = new char[name_date[1].length() + 1];
|
char *date_status = new char[name_date[1].length() + 1];
|
||||||
main_menu_allocated.push_back({GENERIC_TYPE, date_status, 1});
|
main_menu_allocated.push_back({GENERIC_TYPE, date_status, 1});
|
||||||
strlcpy(date_status, name_date[1].c_str(), name_date[1].length() + 1);
|
strlcpy(date_status, name_date[1].c_str(), name_date[1].length() + 1);
|
||||||
|
|||||||
+2
-2
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user