This commit is contained in:
parent
6c8840b3e5
commit
4b7644bd4f
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ compile_commands.json
|
||||
core*
|
||||
build
|
||||
log
|
||||
complaints
|
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