Vipe: Finish basic prototype
Map data structure which maps dates to std::string events
This commit is contained in:
parent
4c1bc842a4
commit
b9f7c2eeeb
15
README.md
15
README.md
|
@ -39,13 +39,14 @@ This will open the default view mode (month) and display the current month's cal
|
|||
|
||||
The following is a list of things that have been/still have to be completed.
|
||||
|
||||
- basic prototype with vipe (in memory only)
|
||||
- writing a calendar to file
|
||||
- reading a calendar from a file
|
||||
- alerting function
|
||||
- logging
|
||||
- read input from stdin
|
||||
- set reminder
|
||||
- Basic prototype with vipe (in memory only)
|
||||
- Finish all the basic shortcuts
|
||||
- Ability to write a calendar to a file
|
||||
- Ability to read a calendar from a file
|
||||
- Alerting function for errors and issues
|
||||
- Logging / Debug flag
|
||||
- Read input from stdin
|
||||
- Set reminders
|
||||
|
||||
# Contributions
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef CALENDAR_HPP
|
||||
#define CALENDAR_HPP
|
||||
|
||||
#include <tuple>
|
||||
|
||||
struct calendar_information {
|
||||
int current_day;
|
||||
int current_month;
|
||||
|
@ -10,6 +12,11 @@ struct calendar_information {
|
|||
calendar_information();
|
||||
};
|
||||
|
||||
const bool operator<(const calendar_information& first, const calendar_information& second) {
|
||||
return std::tie(first.current_day, first.current_month, first.current_month_days, first.current_year) <
|
||||
std::tie(second.current_day, second.current_month, second.current_month_days, second.current_year);
|
||||
}
|
||||
|
||||
class Calendar {
|
||||
public:
|
||||
static int get_days_in_month(int month, int year);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ncurses.h>
|
||||
#include <signal.h>
|
||||
#include "engine.hpp"
|
||||
|
@ -41,7 +42,6 @@ void Engine::ui_draw(WINDOW *win) {
|
|||
this->ui_top_draw(win);
|
||||
this->ui_bottom_draw(win);
|
||||
wrefresh(win);
|
||||
|
||||
}
|
||||
|
||||
void Engine::ui_month_draw(WINDOW *win) {
|
||||
|
@ -79,32 +79,13 @@ void Engine::ui_bottom_draw(WINDOW *win) {
|
|||
if (VIS_COLORING) wattron(win, COLOR_PAIR(1));
|
||||
|
||||
calendar_information date_info = this->calendar->get_info();
|
||||
mvwprintw(win, LINES-2, 1, "Year: %d, Month: %d, Day: %d", date_info.current_year, date_info.current_month, date_info.current_day);
|
||||
std::string current_view_mode = calendar_view_mode_str[this->view_mode];
|
||||
|
||||
mvwprintw(win, LINES-2, 1, "Year: %d, Month: %d, Day: %d, Mode: %s\n", date_info.current_year, date_info.current_month, date_info.current_day, current_view_mode.c_str());
|
||||
|
||||
if (VIS_COLORING) wattroff(win, COLOR_PAIR(1));
|
||||
}
|
||||
|
||||
void Engine::ui_dialog_draw(WINDOW *win) {
|
||||
int lines = LINES/2, cols = COLS/2;
|
||||
int y_center = (LINES/2)-(lines/2), x_center = (COLS/2)-(cols/2);
|
||||
|
||||
this->dialog = newwin(lines, cols, y_center, x_center);
|
||||
|
||||
box(this->dialog, 0, 0);
|
||||
|
||||
char str[200];
|
||||
|
||||
mvwprintw(this->dialog, 1, 1, "Enter your name lol: ");
|
||||
wrefresh(this->dialog);
|
||||
|
||||
mvwgetnstr(this->dialog, 2, 1, str, 200);
|
||||
|
||||
wprintw(this->dialog, "Press q to save or r to retake");
|
||||
|
||||
wrefresh(this->dialog);
|
||||
|
||||
}
|
||||
|
||||
void Engine::input_handle_month(WINDOW *win) {
|
||||
char key = getch();
|
||||
|
||||
|
@ -162,28 +143,58 @@ void Engine::input_handle_month(WINDOW *win) {
|
|||
|
||||
this->active_cell = 0;
|
||||
break;
|
||||
case 'i':
|
||||
endwin();
|
||||
int link[2];
|
||||
char foo[4096];
|
||||
case 'i': {
|
||||
int vipe_out[2], vipe_in[2];
|
||||
char output_buffer[4096];
|
||||
memset(output_buffer, 0, sizeof(output_buffer));
|
||||
|
||||
pipe(link);
|
||||
pipe(vipe_out);
|
||||
pipe(vipe_in);
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == 0) {
|
||||
dup2(link[1], STDOUT_FILENO);
|
||||
close(link[0]);
|
||||
close(link[1]);
|
||||
dup2(vipe_in[0], STDIN_FILENO);
|
||||
dup2(vipe_out[1], STDOUT_FILENO);
|
||||
|
||||
close(vipe_in[0]);
|
||||
close(vipe_in[1]);
|
||||
close(vipe_out[0]);
|
||||
close(vipe_out[1]);
|
||||
|
||||
system("vipe");
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
close(link[1]);
|
||||
int nbytes = read(link[0], foo, sizeof(foo));
|
||||
printw("Output of vipe: %s\n", foo);
|
||||
close(vipe_in[0]);
|
||||
close(vipe_out[1]);
|
||||
|
||||
std::string event = this->events_map[this->calendar->get_info()];
|
||||
write(vipe_in[1], event.c_str(), event.length());
|
||||
close(vipe_in[1]);
|
||||
|
||||
int nbytes = read(vipe_out[0], output_buffer, sizeof(output_buffer));
|
||||
this->events_map[this->calendar->get_info()] = output_buffer;
|
||||
}
|
||||
|
||||
endwin();
|
||||
break;
|
||||
}
|
||||
case 'g':
|
||||
this->calendar->set_day(1);
|
||||
this->active_cell = 0;
|
||||
break;
|
||||
case 'G':
|
||||
this->calendar->set_day(this->calendar->get_info().current_month_days);
|
||||
this->active_cell = this->calendar->get_info().current_month_days-1;
|
||||
break;
|
||||
case 't':
|
||||
this->view_mode = WEEK_VIEW;
|
||||
wclear(win);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::input_handle_week(WINDOW *win) {
|
||||
|
||||
}
|
||||
|
||||
void Engine::input_handle_months(WINDOW *win) {
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#ifndef ENGINE_HPP
|
||||
#define ENGINE_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <ncurses.h>
|
||||
#include <vector>
|
||||
// #include <unordered_map>
|
||||
#include <map>
|
||||
#include "../calendar/calendar.hpp"
|
||||
#include "../global/global.hpp"
|
||||
|
||||
|
@ -17,6 +20,12 @@ enum calendar_view_mode {
|
|||
MONTHS_VIEW
|
||||
};
|
||||
|
||||
std::string calendar_view_mode_str[] = {
|
||||
"MONTH_VIEW",
|
||||
"WEEK_VIEW",
|
||||
"MONTHS_VIEW"
|
||||
};
|
||||
|
||||
// title: drawing engine
|
||||
// description: use for drawing the TUI and interact with the cells
|
||||
class Engine {
|
||||
|
@ -32,9 +41,12 @@ class Engine {
|
|||
void ui_top_draw(WINDOW *win);
|
||||
|
||||
void input_handle_month(WINDOW *win);
|
||||
void input_handle_week(WINDOW *win);
|
||||
void input_handle_months(WINDOW *win);
|
||||
|
||||
Calendar *calendar;
|
||||
// std::unordered_map<calendar_information, std::string> events_map;
|
||||
std::map<calendar_information, std::string> events_map;
|
||||
int active_cell;
|
||||
|
||||
calendar_view_mode view_mode;
|
||||
|
|
|
@ -12,12 +12,14 @@ WINDOW *main_win;
|
|||
void sig_winch(int sig) {
|
||||
if (isendwin()) return;
|
||||
endwin();
|
||||
|
||||
wclear(main_win);
|
||||
wrefresh(main_win);
|
||||
|
||||
wresize(main_win, LINES, COLS);
|
||||
|
||||
mvwin(main_win, 0, 0);
|
||||
|
||||
// redraw the TUI after the resize signal
|
||||
engine.ui_draw(main_win);
|
||||
|
||||
|
@ -51,14 +53,13 @@ int main() {
|
|||
// handle required signals
|
||||
signals();
|
||||
|
||||
|
||||
for (;;) {
|
||||
wclear(main_win);
|
||||
wrefresh(main_win);
|
||||
engine.ui_draw(main_win);
|
||||
|
||||
if (engine.view_mode == MONTH_VIEW)
|
||||
engine.input_handle_month(main_win);
|
||||
if (engine.view_mode == WEEK_VIEW)
|
||||
engine.input_handle_week(main_win);
|
||||
else if (engine.view_mode == MONTHS_VIEW)
|
||||
engine.input_handle_months(main_win);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user