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.
|
The following is a list of things that have been/still have to be completed.
|
||||||
|
|
||||||
- basic prototype with vipe (in memory only)
|
- Basic prototype with vipe (in memory only)
|
||||||
- writing a calendar to file
|
- Finish all the basic shortcuts
|
||||||
- reading a calendar from a file
|
- Ability to write a calendar to a file
|
||||||
- alerting function
|
- Ability to read a calendar from a file
|
||||||
- logging
|
- Alerting function for errors and issues
|
||||||
- read input from stdin
|
- Logging / Debug flag
|
||||||
- set reminder
|
- Read input from stdin
|
||||||
|
- Set reminders
|
||||||
|
|
||||||
# Contributions
|
# Contributions
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef CALENDAR_HPP
|
#ifndef CALENDAR_HPP
|
||||||
#define CALENDAR_HPP
|
#define CALENDAR_HPP
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
struct calendar_information {
|
struct calendar_information {
|
||||||
int current_day;
|
int current_day;
|
||||||
int current_month;
|
int current_month;
|
||||||
|
@ -10,6 +12,11 @@ struct calendar_information {
|
||||||
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 {
|
class Calendar {
|
||||||
public:
|
public:
|
||||||
static int get_days_in_month(int month, int year);
|
static int get_days_in_month(int month, int year);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "engine.hpp"
|
#include "engine.hpp"
|
||||||
|
@ -41,7 +42,6 @@ void Engine::ui_draw(WINDOW *win) {
|
||||||
this->ui_top_draw(win);
|
this->ui_top_draw(win);
|
||||||
this->ui_bottom_draw(win);
|
this->ui_bottom_draw(win);
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::ui_month_draw(WINDOW *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));
|
if (VIS_COLORING) wattron(win, COLOR_PAIR(1));
|
||||||
|
|
||||||
calendar_information date_info = this->calendar->get_info();
|
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));
|
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) {
|
void Engine::input_handle_month(WINDOW *win) {
|
||||||
char key = getch();
|
char key = getch();
|
||||||
|
|
||||||
|
@ -162,28 +143,58 @@ void Engine::input_handle_month(WINDOW *win) {
|
||||||
|
|
||||||
this->active_cell = 0;
|
this->active_cell = 0;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i': {
|
||||||
endwin();
|
int vipe_out[2], vipe_in[2];
|
||||||
int link[2];
|
char output_buffer[4096];
|
||||||
char foo[4096];
|
memset(output_buffer, 0, sizeof(output_buffer));
|
||||||
|
|
||||||
pipe(link);
|
pipe(vipe_out);
|
||||||
|
pipe(vipe_in);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
dup2(link[1], STDOUT_FILENO);
|
dup2(vipe_in[0], STDIN_FILENO);
|
||||||
close(link[0]);
|
dup2(vipe_out[1], STDOUT_FILENO);
|
||||||
close(link[1]);
|
|
||||||
|
close(vipe_in[0]);
|
||||||
|
close(vipe_in[1]);
|
||||||
|
close(vipe_out[0]);
|
||||||
|
close(vipe_out[1]);
|
||||||
|
|
||||||
system("vipe");
|
system("vipe");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
close(link[1]);
|
close(vipe_in[0]);
|
||||||
int nbytes = read(link[0], foo, sizeof(foo));
|
close(vipe_out[1]);
|
||||||
printw("Output of vipe: %s\n", foo);
|
|
||||||
|
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;
|
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) {
|
void Engine::input_handle_months(WINDOW *win) {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#ifndef ENGINE_HPP
|
#ifndef ENGINE_HPP
|
||||||
#define ENGINE_HPP
|
#define ENGINE_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
// #include <unordered_map>
|
||||||
|
#include <map>
|
||||||
#include "../calendar/calendar.hpp"
|
#include "../calendar/calendar.hpp"
|
||||||
#include "../global/global.hpp"
|
#include "../global/global.hpp"
|
||||||
|
|
||||||
|
@ -17,6 +20,12 @@ enum calendar_view_mode {
|
||||||
MONTHS_VIEW
|
MONTHS_VIEW
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string calendar_view_mode_str[] = {
|
||||||
|
"MONTH_VIEW",
|
||||||
|
"WEEK_VIEW",
|
||||||
|
"MONTHS_VIEW"
|
||||||
|
};
|
||||||
|
|
||||||
// title: drawing engine
|
// title: drawing engine
|
||||||
// description: use for drawing the TUI and interact with the cells
|
// description: use for drawing the TUI and interact with the cells
|
||||||
class Engine {
|
class Engine {
|
||||||
|
@ -32,9 +41,12 @@ class Engine {
|
||||||
void ui_top_draw(WINDOW *win);
|
void ui_top_draw(WINDOW *win);
|
||||||
|
|
||||||
void input_handle_month(WINDOW *win);
|
void input_handle_month(WINDOW *win);
|
||||||
|
void input_handle_week(WINDOW *win);
|
||||||
void input_handle_months(WINDOW *win);
|
void input_handle_months(WINDOW *win);
|
||||||
|
|
||||||
Calendar *calendar;
|
Calendar *calendar;
|
||||||
|
// std::unordered_map<calendar_information, std::string> events_map;
|
||||||
|
std::map<calendar_information, std::string> events_map;
|
||||||
int active_cell;
|
int active_cell;
|
||||||
|
|
||||||
calendar_view_mode view_mode;
|
calendar_view_mode view_mode;
|
||||||
|
|
|
@ -12,12 +12,14 @@ WINDOW *main_win;
|
||||||
void sig_winch(int sig) {
|
void sig_winch(int sig) {
|
||||||
if (isendwin()) return;
|
if (isendwin()) return;
|
||||||
endwin();
|
endwin();
|
||||||
|
|
||||||
wclear(main_win);
|
wclear(main_win);
|
||||||
wrefresh(main_win);
|
wrefresh(main_win);
|
||||||
|
|
||||||
wresize(main_win, LINES, COLS);
|
wresize(main_win, LINES, COLS);
|
||||||
|
|
||||||
mvwin(main_win, 0, 0);
|
mvwin(main_win, 0, 0);
|
||||||
|
|
||||||
// redraw the TUI after the resize signal
|
// redraw the TUI after the resize signal
|
||||||
engine.ui_draw(main_win);
|
engine.ui_draw(main_win);
|
||||||
|
|
||||||
|
@ -51,14 +53,13 @@ int main() {
|
||||||
// handle required signals
|
// handle required signals
|
||||||
signals();
|
signals();
|
||||||
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
wclear(main_win);
|
|
||||||
wrefresh(main_win);
|
|
||||||
engine.ui_draw(main_win);
|
engine.ui_draw(main_win);
|
||||||
|
|
||||||
if (engine.view_mode == MONTH_VIEW)
|
if (engine.view_mode == MONTH_VIEW)
|
||||||
engine.input_handle_month(main_win);
|
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)
|
else if (engine.view_mode == MONTHS_VIEW)
|
||||||
engine.input_handle_months(main_win);
|
engine.input_handle_months(main_win);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user