Frontend: Add color support

This commit is contained in:
osamu-kj 2023-04-22 22:36:18 +02:00
parent db58c196a9
commit dea21b138a
4 changed files with 51 additions and 15 deletions

View File

@ -15,28 +15,38 @@ Engine::~Engine() {
delete this->calendar; delete this->calendar;
} }
void Engine::draw(WINDOW *win) { void Engine::ui_draw(WINDOW *win) {
this->cells_table.clear(); this->cells_table.clear();
box(win, 0, 0); box(win, 0, 0);
calendar_information date_info = this->calendar->get_info();
switch (this->view_mode) { switch (this->view_mode) {
case MONTH_VIEW: case MONTH_VIEW:
for (int i = 1; i <= date_info.current_month_days; i++) this->ui_month_draw(win);
mvwprintw(win, i, 3, "D%d", i);
break; break;
case MONTHS_VIEW: case MONTHS_VIEW:
for (int i = 1; i <= 12; i++) this->ui_months_draw(win);
wprintw(win, "M%d", i);
break; break;
} }
wprintw(win, "\n"); this->ui_bottom_draw(win);
mvwprintw(win, LINES-1, 0, "Year: %d, Month: %d, Day: %d", date_info.current_year, date_info.current_month, date_info.current_day);
wrefresh(win); wrefresh(win);
} }
void Engine::ui_month_draw(WINDOW *win) {
}
void Engine::ui_months_draw(WINDOW *win) {
}
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);
if (VIS_COLORING) wattroff(win, COLOR_PAIR(1));
}

View File

@ -4,6 +4,7 @@
#include <ncurses.h> #include <ncurses.h>
#include <vector> #include <vector>
#include "../calendar/calendar.hpp" #include "../calendar/calendar.hpp"
#include "../global/global.hpp"
struct engine_child { struct engine_child {
int x; int x;
@ -22,7 +23,10 @@ class Engine {
Engine(int padding = 10, calendar_view_mode view_mode = MONTH_VIEW); Engine(int padding = 10, calendar_view_mode view_mode = MONTH_VIEW);
~Engine(); ~Engine();
void draw(WINDOW *win); void ui_draw(WINDOW *win);
void ui_month_draw(WINDOW *win);
void ui_months_draw(WINDOW *win);
void ui_bottom_draw(WINDOW *win);
Calendar *calendar; Calendar *calendar;

8
src/global/global.hpp Normal file
View File

@ -0,0 +1,8 @@
#ifndef VIS_GLOBAL
#define VIS_GLOBAL
#include <ncurses.h>
#define VIS_COLORING has_colors() && can_change_color()
#endif

View File

@ -4,6 +4,7 @@
#include <ncurses.h> #include <ncurses.h>
#include "calendar/calendar.hpp" #include "calendar/calendar.hpp"
#include "engine/engine.hpp" #include "engine/engine.hpp"
#include "global/global.hpp"
Engine engine = Engine(10, MONTH_VIEW); Engine engine = Engine(10, MONTH_VIEW);
WINDOW *main_win; WINDOW *main_win;
@ -17,7 +18,7 @@ void sig_winch(int sig) {
wresize(main_win, LINES, COLS); wresize(main_win, LINES, COLS);
// redraw the TUI after the resize signal // redraw the TUI after the resize signal
engine.draw(main_win); engine.ui_draw(main_win);
flushinp(); flushinp();
} }
@ -31,15 +32,29 @@ int main() {
refresh(); refresh();
noecho(); noecho();
curs_set(0); // invisible cursor
refresh();
main_win = newwin(LINES, COLS, 0, 0); main_win = newwin(LINES, COLS, 0, 0);
if (VIS_COLORING) {
start_color();
use_default_colors();
init_color(COLOR_BLACK, 0, 0, 0);
init_color(COLOR_WHITE, 1000, 1000, 1000);
init_pair(0, COLOR_WHITE, COLOR_BLACK);
init_pair(1, COLOR_BLACK, COLOR_WHITE);
}
// handle required signals // handle required signals
signals(); signals();
for (;;) { for (;;) {
wclear(main_win); wclear(main_win);
wrefresh(main_win); wrefresh(main_win);
engine.draw(main_win); engine.ui_draw(main_win);
char ch = getch(); char ch = getch();
int month; int month;
@ -65,7 +80,6 @@ int main() {
} }
} }
endwin(); endwin();
return 0; return 0;