Vis: Remove unnecessary code + Update README.md

This commit is contained in:
osamu-kj 2023-05-20 02:08:12 +02:00
parent 17a621b787
commit 15f8c9534f
7 changed files with 71 additions and 138 deletions

View File

@ -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. 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 ![Vi Scheduler - Preview](./preview/preview.png)
- Vim-like navigation and editing commands
- Multiple view modes: month, week
# Dependencies # 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) - [The Ncurses library](https://invisible-island.net/ncurses/announce.html)
- [Moreutils](https://joeyh.name/code/moreutils/) - [Moreutils](https://joeyh.name/code/moreutils/)
@ -25,7 +22,7 @@ For installation, you can run `sudo make install` (from the /build directory)
# Usage # 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` 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. 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)~~
- Finish all the basic shortcuts - ~~Finish all the basic shortcuts~~
- Ability to write a calendar to a file - ~~Ability to write a calendar to a file~~
- Ability to read a calendar from a file - ~~Ability to read a calendar from a file~~
- Alerting function for errors and issues - Alerting function for errors and issues
- Logging / Debug flag - Logging / Debug flag
- Read input from stdin - Read input from stdin
- Set reminders
# Contributions # 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 # License

BIN
preview/preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -67,6 +67,9 @@ Calendar::Calendar(calendar_information *preinfo) {
} }
// https://stackoverflow.com/questions/6054016/c-program-to-find-day-of-week-given-date // 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) { int get_weekday(calendar_information *date_info) {
if (date_info == nullptr) if (date_info == nullptr)
return 0; return 0;

View File

@ -5,10 +5,8 @@
#include <signal.h> #include <signal.h>
#include "engine.hpp" #include "engine.hpp"
Engine::Engine(int padding, calendar_view_mode view_mode) { Engine::Engine(int padding) {
this->padding = padding; this->padding = padding;
this->view_mode = view_mode;
this->cells_table = std::vector<engine_child>();
calendar_information date_info = calendar_information(); calendar_information date_info = calendar_information();
this->calendar = new Calendar(&date_info); this->calendar = new Calendar(&date_info);
@ -24,38 +22,24 @@ void Engine::ui_draw(WINDOW *win) {
getmaxyx(win, screen_height, screen_width); getmaxyx(win, screen_height, screen_width);
if (screen_height < 25 || screen_width < 70) { 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; return;
} }
this->input_block = false; low_res_flag = 0;
this->cells_table.clear();
box(win, 0, 0); box(win, 0, 0);
wrefresh(win);
keypad(win, TRUE); keypad(win, TRUE);
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
switch (this->view_mode) {
case MONTH_VIEW:
this->ui_month_draw(win); 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_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_warning_draw(WINDOW *win, const char *message) { void Engine::ui_warning_draw(WINDOW *win, const char *message) {
this->input_block = true; low_res_flag = 1;
mvwprintw(win, 0, 0, "%s", message); 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)); int y_location = this->padding + (q/(date_info.current_month_days/7) * (i/7));
// check if day has an event // check if day has an event
// TOOD: Temporary solution // TODO: Temporary solution
calendar_information tmp_date = date_info; calendar_information tmp_date = date_info;
tmp_date.current_day = i+1; 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) { void Engine::ui_top_draw(WINDOW *win) {
if (VIS_COLORING) wattron(win, COLOR_PAIR(1)); 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)); if (VIS_COLORING) wattron(win, COLOR_PAIR(1));
calendar_information date_info = this->calendar->get_info(); 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)); if (VIS_COLORING) wattroff(win, COLOR_PAIR(1));
} }
@ -125,56 +100,18 @@ void Engine::ui_bottom_draw(WINDOW *win) {
void Engine::input_handle(WINDOW *win) { void Engine::input_handle(WINDOW *win) {
char key = getch(); char key = getch();
if (this->input_block) if (key == ERR) return;
return; if (low_res_flag) return;
if (this->input_handle_universal(win, key)) if (this->input_handle_universal(win, key))
return; return;
if (this->view_mode == MONTH_VIEW)
this->input_handle_month(win, key); 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.
} }
bool Engine::input_handle_universal(WINDOW *win, char key) { bool Engine::input_handle_universal(WINDOW *win, char key) {
int day; int day;
switch (key) { 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(); endwin();
int vipe_out[2], vipe_in[2]; int vipe_out[2], vipe_in[2];
@ -239,11 +176,41 @@ bool Engine::input_handle_universal(WINDOW *win, char key) {
} }
void Engine::input_handle_month(WINDOW *win, char key) { void Engine::input_handle_month(WINDOW *win, char key) {
calendar_information date_info = this->calendar->get_info(); calendar_information date_info = this->calendar->get_info();
int month; int day, month;
switch (key) { 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': case 'u':
if (this->calendar->get_info().current_month <= 1) break; 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) { calendar_information Engine::parse_date(std::string date) {
char *token = strtok((char *) date.c_str(), "."); char *token = strtok((char *) date.c_str(), ".");
std::vector<int> tokens; std::vector<int> tokens;
@ -334,7 +293,6 @@ void Engine::open_calendar(char *filename) {
std::string line; std::string line;
while (std::getline(this->calendar_file, line)) while (std::getline(this->calendar_file, line))
this->parse_line(line); this->parse_line(line);
} }
bool Engine::write_calendar() { bool Engine::write_calendar() {

View File

@ -11,17 +11,6 @@
#include "../calendar/calendar.hpp" #include "../calendar/calendar.hpp"
#include "../global/global.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[] = { std::string weekday_prefixes[] = {
"Sun", "Sun",
"Mon", "Mon",
@ -32,24 +21,16 @@ std::string weekday_prefixes[] = {
"Sat" "Sat"
}; };
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 {
public: public:
Engine(int padding, calendar_view_mode view_mode); Engine(int padding);
~Engine(); ~Engine();
void ui_draw(WINDOW *win); void ui_draw(WINDOW *win);
void ui_warning_draw(WINDOW *win, const char *message); void ui_warning_draw(WINDOW *win, const char *message);
void ui_month_draw(WINDOW *win); 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_bottom_draw(WINDOW *win);
void ui_top_draw(WINDOW *win); void ui_top_draw(WINDOW *win);
@ -57,8 +38,6 @@ class Engine {
void input_handle(WINDOW* win); void input_handle(WINDOW* win);
bool input_handle_universal(WINDOW *win, char key); bool input_handle_universal(WINDOW *win, char key);
void input_handle_month(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); calendar_information parse_date(std::string date);
void parse_line(std::string line); void parse_line(std::string line);
@ -70,10 +49,8 @@ class Engine {
std::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;
int padding; // padding int padding; // padding
private: private:
std::vector<engine_child> cells_table;
std::fstream calendar_file; std::fstream calendar_file;
char * calendar_file_location; char * calendar_file_location;
}; };

View File

@ -1,8 +1,11 @@
#ifndef VIS_GLOBAL #ifndef VIS_GLOBAL
#define VIS_GLOBAL #define VIS_GLOBAL
#include <signal.h>
#include <ncurses.h> #include <ncurses.h>
#define VIS_COLORING has_colors() && can_change_color() #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 #endif

View File

@ -6,25 +6,11 @@
#include "engine/engine.hpp" #include "engine/engine.hpp"
#include "global/global.hpp" #include "global/global.hpp"
Engine engine(10, MONTH_VIEW); Engine engine(10);
WINDOW *main_win; WINDOW *main_win;
void sig_winch(int sig) { void sig_winch(int sig) {
if (isendwin()) return; winch_flag = 1;
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;
} }
void signals() { void signals() {
@ -64,6 +50,7 @@ int main(int argc, char **argv) {
curs_set(0); // invisible cursor curs_set(0); // invisible cursor
noecho(); noecho();
halfdelay(1);
refresh(); refresh();
main_win = newwin(LINES, COLS, 0, 0); main_win = newwin(LINES, COLS, 0, 0);
@ -84,8 +71,17 @@ int main(int argc, char **argv) {
signals(); signals();
for (;;) { 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); engine.input_handle(main_win);
} }