diff --git a/README.md b/README.md index bd2ded5..f543adf 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,13 @@ Vi Scheduler (VIS) is a lightweight tool that brings a Vim-like calendar to your terminal. It allows you to quickly view and edit your schedule, appointments, and tasks without leaving your command-line interface. -Built using C++ and the Ncurses library, Vis offers a fast and efficient way to manage your time in the terminal. It suppors various navigation and editing commands inspired by Vim, such as navigating between days or months, adding and deleting events, and setting reminders. +Built using C++ and the Ncurses library, vis offers a fast and efficient way to manage your time in the terminal. It suppors various navigation and editing commands inspired by Vim, such as navigating between days or months, adding and deleting events. -# Features - - - Vim-like navigation and editing commands - - Multiple view modes: month, week +![Vi Scheduler - Preview](./preview/preview.png) # Dependencies -The following is a list of dependencies that your system needs in order to be able to run Vis. +The following is a list of dependencies that your system needs in order to be able to run vis. - [The Ncurses library](https://invisible-island.net/ncurses/announce.html) - [Moreutils](https://joeyh.name/code/moreutils/) @@ -25,7 +22,7 @@ For installation, you can run `sudo make install` (from the /build directory) # Usage -To start Vis simply run the `vis` binary in your terminal alongside the name of the calendar file. +To start vis simply run the `vis` binary in your terminal alongside the name of the calendar file. For example: `vis school.cal` @@ -44,17 +41,16 @@ 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)~~ - - Finish all the basic shortcuts - - Ability to write a calendar to a file - - Ability to read a calendar from a file + - ~~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 -Contributions and feedback are welcome! If you have any ideas or suggestions for improving Vis, please submit a pull request or open an issue on Github. Let's make the FOSS community better, together! +Contributions and feedback are welcome! If you have any ideas or suggestions for improving vis, please submit a pull request or open an issue on Github. Let's make the FOSS community better, together! # License diff --git a/preview/preview.png b/preview/preview.png new file mode 100644 index 0000000..e808e0d Binary files /dev/null and b/preview/preview.png differ diff --git a/src/calendar/calendar.cpp b/src/calendar/calendar.cpp index a3604c0..3670cbc 100644 --- a/src/calendar/calendar.cpp +++ b/src/calendar/calendar.cpp @@ -67,6 +67,9 @@ Calendar::Calendar(calendar_information *preinfo) { } // https://stackoverflow.com/questions/6054016/c-program-to-find-day-of-week-given-date +// RETURNS: +// Number of the given day in its week. +// Note: it starts with sunday being 0 int get_weekday(calendar_information *date_info) { if (date_info == nullptr) return 0; diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index f5cc18b..9b3523f 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -5,10 +5,8 @@ #include #include "engine.hpp" -Engine::Engine(int padding, calendar_view_mode view_mode) { +Engine::Engine(int padding) { this->padding = padding; - this->view_mode = view_mode; - this->cells_table = std::vector(); calendar_information date_info = calendar_information(); this->calendar = new Calendar(&date_info); @@ -24,38 +22,24 @@ void Engine::ui_draw(WINDOW *win) { getmaxyx(win, screen_height, screen_width); if (screen_height < 25 || screen_width < 70) { - this->ui_warning_draw(win, "Window resolution too small, please resize it."); return; + this->ui_warning_draw(win, "Window resolution too small, please resize it."); return; } - this->input_block = false; - this->cells_table.clear(); - + low_res_flag = 0; box(win, 0, 0); - wrefresh(win); keypad(win, TRUE); keypad(stdscr, TRUE); - switch (this->view_mode) { - case MONTH_VIEW: - this->ui_month_draw(win); - break; - case WEEK_VIEW: - this->ui_week_draw(win); - break; - case MONTHS_VIEW: - this->ui_months_draw(win); - break; - } - + this->ui_month_draw(win); this->ui_top_draw(win); this->ui_bottom_draw(win); wrefresh(win); } void Engine::ui_warning_draw(WINDOW *win, const char *message) { - this->input_block = true; + low_res_flag = 1; mvwprintw(win, 0, 0, "%s", message); @@ -71,7 +55,7 @@ void Engine::ui_month_draw(WINDOW *win) { int y_location = this->padding + (q/(date_info.current_month_days/7) * (i/7)); // check if day has an event - // TOOD: Temporary solution + // TODO: Temporary solution calendar_information tmp_date = date_info; tmp_date.current_day = i+1; @@ -95,14 +79,6 @@ void Engine::ui_month_draw(WINDOW *win) { } } -void Engine::ui_week_draw(WINDOW *win) { - // TODO -} - -void Engine::ui_months_draw(WINDOW *win) { - // TODO -} - void Engine::ui_top_draw(WINDOW *win) { if (VIS_COLORING) wattron(win, COLOR_PAIR(1)); @@ -115,9 +91,8 @@ void Engine::ui_bottom_draw(WINDOW *win) { if (VIS_COLORING) wattron(win, COLOR_PAIR(1)); calendar_information date_info = this->calendar->get_info(); - 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()); + mvwprintw(win, LINES-2, 1, "Year: %d, Month: %d, Day: %d\n", date_info.current_year, date_info.current_month, date_info.current_day); if (VIS_COLORING) wattroff(win, COLOR_PAIR(1)); } @@ -125,57 +100,19 @@ void Engine::ui_bottom_draw(WINDOW *win) { void Engine::input_handle(WINDOW *win) { char key = getch(); - if (this->input_block) - return; + if (key == ERR) return; + if (low_res_flag) return; if (this->input_handle_universal(win, key)) return; - if (this->view_mode == MONTH_VIEW) - this->input_handle_month(win, key); - else if (this->view_mode == WEEK_VIEW) - this->input_handle_week(win, key); - else if (this->view_mode == MONTHS_VIEW) - this->input_handle_months(win, key); - - // fuc. + this->input_handle_month(win, key); } bool Engine::input_handle_universal(WINDOW *win, char key) { int day; switch (key) { - case 'h': - if (this->calendar->get_info().current_day <= 1) break; - - day = this->calendar->get_info().current_day; - this->calendar->set_day(--day); - - --this->active_cell; - break; - case 'l': - if (this->calendar->get_info().current_day >= this->calendar->get_info().current_month_days) break; - - day = this->calendar->get_info().current_day; - this->calendar->set_day(++day); - - ++this->active_cell; - break; - case 'j': - if (this->calendar->get_info().current_day+7 > this->calendar->get_info().current_month_days) break; - - day = this->calendar->get_info().current_day; - this->calendar->set_day(day+7); - - this->active_cell += 7; - break; - case 'k': - if (this->calendar->get_info().current_day-7 < 1) break; - day = this->calendar->get_info().current_day; - this->calendar->set_day(day-7); - - this->active_cell -= 7; - break; - case 'i': { // TODO: Break down this monstrocity of a case + case 'i': { // TODO: Break down this monstrocity of a case endwin(); int vipe_out[2], vipe_in[2]; char output_buffer[4096]; @@ -239,11 +176,41 @@ bool Engine::input_handle_universal(WINDOW *win, char key) { } void Engine::input_handle_month(WINDOW *win, char key) { - calendar_information date_info = this->calendar->get_info(); - int month; + int day, month; switch (key) { + case 'h': + if (this->calendar->get_info().current_day <= 1) break; + + day = this->calendar->get_info().current_day; + this->calendar->set_day(--day); + + --this->active_cell; + break; + case 'l': + if (this->calendar->get_info().current_day >= this->calendar->get_info().current_month_days) break; + + day = this->calendar->get_info().current_day; + this->calendar->set_day(++day); + + ++this->active_cell; + break; + case 'j': + if (this->calendar->get_info().current_day+7 > this->calendar->get_info().current_month_days) break; + + day = this->calendar->get_info().current_day; + this->calendar->set_day(day+7); + + this->active_cell += 7; + break; + case 'k': + if (this->calendar->get_info().current_day-7 < 1) break; + day = this->calendar->get_info().current_day; + this->calendar->set_day(day-7); + + this->active_cell -= 7; + break; case 'u': if (this->calendar->get_info().current_month <= 1) break; @@ -273,14 +240,6 @@ void Engine::input_handle_month(WINDOW *win, char key) { } } -void Engine::input_handle_week(WINDOW *win, char key) { - // TODO -} - -void Engine::input_handle_months(WINDOW *win, char key) { - // TODO -} - calendar_information Engine::parse_date(std::string date) { char *token = strtok((char *) date.c_str(), "."); std::vector tokens; @@ -334,7 +293,6 @@ void Engine::open_calendar(char *filename) { std::string line; while (std::getline(this->calendar_file, line)) this->parse_line(line); - } bool Engine::write_calendar() { diff --git a/src/engine/engine.hpp b/src/engine/engine.hpp index 5bb7639..a54b007 100644 --- a/src/engine/engine.hpp +++ b/src/engine/engine.hpp @@ -11,17 +11,6 @@ #include "../calendar/calendar.hpp" #include "../global/global.hpp" -struct engine_child { - int x; - int y; -}; - -enum calendar_view_mode { - MONTH_VIEW = 0, - WEEK_VIEW, - MONTHS_VIEW -}; - std::string weekday_prefixes[] = { "Sun", "Mon", @@ -32,24 +21,16 @@ std::string weekday_prefixes[] = { "Sat" }; -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 { public: - Engine(int padding, calendar_view_mode view_mode); + Engine(int padding); ~Engine(); void ui_draw(WINDOW *win); void ui_warning_draw(WINDOW *win, const char *message); void ui_month_draw(WINDOW *win); - void ui_week_draw(WINDOW *win); - void ui_months_draw(WINDOW *win); void ui_bottom_draw(WINDOW *win); void ui_top_draw(WINDOW *win); @@ -57,8 +38,6 @@ class Engine { void input_handle(WINDOW* win); bool input_handle_universal(WINDOW *win, char key); void input_handle_month(WINDOW *win, char key); - void input_handle_week(WINDOW *win, char key); - void input_handle_months(WINDOW *win, char key); calendar_information parse_date(std::string date); void parse_line(std::string line); @@ -70,10 +49,8 @@ class Engine { std::map events_map; int active_cell; - calendar_view_mode view_mode; int padding; // padding private: - std::vector cells_table; std::fstream calendar_file; char * calendar_file_location; }; diff --git a/src/global/global.hpp b/src/global/global.hpp index 5dfc357..229b40a 100644 --- a/src/global/global.hpp +++ b/src/global/global.hpp @@ -1,8 +1,11 @@ #ifndef VIS_GLOBAL #define VIS_GLOBAL +#include #include #define VIS_COLORING has_colors() && can_change_color() +volatile sig_atomic_t winch_flag = 0; // DESCRIPTION: flags if the resolution of the terminal has changed +volatile sig_atomic_t low_res_flag = 0; // DESCRIPTION: flags if the resolution of the terminal is too small #endif diff --git a/src/main.cpp b/src/main.cpp index db85abd..c4c7fd9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,25 +6,11 @@ #include "engine/engine.hpp" #include "global/global.hpp" -Engine engine(10, MONTH_VIEW); +Engine engine(10); 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); - - // if the resolution is too small, output a warning - // else redraw the TUI - engine.ui_draw(main_win); - - flushinp(); - return; + winch_flag = 1; } void signals() { @@ -64,6 +50,7 @@ int main(int argc, char **argv) { curs_set(0); // invisible cursor noecho(); + halfdelay(1); refresh(); main_win = newwin(LINES, COLS, 0, 0); @@ -84,8 +71,17 @@ int main(int argc, char **argv) { signals(); for (;;) { - engine.ui_draw(main_win); + if (winch_flag) { + winch_flag = 0; + endwin(); + wrefresh(main_win); + wclear(main_win); + wresize(main_win, LINES, COLS); + mvwin(main_win, 0, 0); + } + + engine.ui_draw(main_win); engine.input_handle(main_win); }