#include "view.h"
#include "util.h"
+/* For testing */
+#pragma weak COMPACT
+
/* Static data */
static FILE *debug_fd = NULL;
}
/* Log to status bar */
- if (stdscr) {
+ if (&COMPACT && stdscr) {
+ int rev = COMPACT ? A_BOLD : 0;
va_copy(tmp, ap);
- mvhline(LINES-2, 0, ACS_HLINE, COLS);
+ if (!COMPACT)
+ mvhline(LINES-2, 0, ACS_HLINE, COLS);
move(LINES-1, 0);
- attron(COLOR_PAIR(COLOR_ERROR));
+ attron(COLOR_PAIR(COLOR_ERROR) | rev);
vwprintw(stdscr, fmt, tmp);
- attroff(COLOR_PAIR(COLOR_ERROR));
- clrtoeol();
+ attroff(COLOR_PAIR(COLOR_ERROR) | rev);
+ if (!COMPACT)
+ clrtoeol();
}
}
WINDOW *win;
} view_t;
-/* Data */
+/* View data */
view_t views[] = {
{ "Day", day_init, day_size, day_draw, day_run, {KEY_F(1), '1', } },
{ "Week", week_init, week_size, week_draw, week_run, {KEY_F(2), '2', } },
{ "Help", help_init, help_size, help_draw, help_run, {KEY_F(8), '8', '?'} },
};
-int active = 0;
+/* Config data */
+int COMPACT = 0;
+int ACTIVE = 0;
/* Local functions */
static void draw_header(void)
move(0, 0);
attron(COLOR_PAIR(COLOR_TITLE));
for (int i = 0; i < N_ELEMENTS(views); i++) {
- if (i == active)
+ if (i == ACTIVE)
attron(A_BOLD);
printw("%s ", views[i].name);
- if (i == active)
+ if (i == ACTIVE)
attroff(A_BOLD);
}
attroff(COLOR_PAIR(COLOR_TITLE));
- mvhline(1, 0, ACS_HLINE, COLS);
+ if (!COMPACT)
+ mvhline(1, 0, ACS_HLINE, COLS);
refresh();
}
/* View init */
void view_init(void)
{
+ int hdr = COMPACT ? 1 : 2;
for (int i = 0; i < N_ELEMENTS(views); i++) {
if (views[i].init) {
- views[i].win = newwin(LINES-2, COLS, 2, 0);
+ views[i].win = newwin(LINES-hdr, COLS, hdr, 0);
views[i].init(views[i].win);
}
}
/* View draw */
void view_resize(void)
{
+ int hdr = COMPACT ? 1 : 2;
for (int i = 0; i < N_ELEMENTS(views); i++) {
- if (views[i].win)
- wresize(views[i].win, LINES-2, COLS);
+ if (views[i].win) {
+ wresize(views[i].win, LINES-hdr, COLS);
+ mvwin(views[i].win, hdr, 0);
+ }
if (views[i].size)
- views[i].size(LINES-2, COLS);
+ views[i].size(LINES-hdr, COLS);
}
}
void view_draw(void)
{
draw_header();
- werase(views[active].win);
- views[active].draw();
- wrefresh(views[active].win);
+ werase(views[ACTIVE].win);
+ views[ACTIVE].draw();
+ wrefresh(views[ACTIVE].win);
}
/* View set */
int view_set(int num)
{
- if (active != num) {
- active = num;
+ if (ACTIVE != num) {
+ ACTIVE = num;
view_draw();
}
return 1;
/* View run */
int view_run(int key, mmask_t btn, int row, int col)
{
+ /* Check for compact mode toggle */
+ if (key == 'c') {
+ COMPACT ^= 1;
+ view_resize();
+ view_draw();
+ return 1;
+ }
+
/* Check for mouse events */
if (key == KEY_MOUSE && row == 0) {
int start = 1;
/* Check for view change */
for (int i = 0; i < N_ELEMENTS(views); i++) {
- if (i == active)
+ if (i == ACTIVE)
continue;
for (int j = 0; j < N_ELEMENTS(views[i].keys); j++)
if (views[i].keys[j] == key)
}
/* Shift windows */
- int num = active;
+ int num = ACTIVE;
int shift = key == KEY_RIGHT ? +1 :
key == KEY_LEFT ? -1 : 0;
while (shift) {
}
/* Pass key to active view */
- return views[active].run(key, btn, row, col);
+ return views[ACTIVE].run(key, btn, row, col);
}
#define COLOR_WORK 8
#define COLOR_OTHER 9
+/* Config data */
+extern int COMPACT;
+extern int ACTIVE;
+
/* Helper functions */
void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w);
void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full);
/* Day init */
void day_init(WINDOW *_win)
{
- win = _win; // lines cols y x
+ win = _win; // lines cols y x
head = derwin(win, 1, COLS, 0, 0);
times = derwin(win, LINES-2-2, 5, 2, 0);
body = derwin(win, LINES-2-2, COLS-6, 2, 6);
/* Day size */
void day_size(int rows, int cols)
{
- wresize(head, 1, cols );
- wresize(times, rows-2, 5);
- wresize(body, rows-2, cols-6);
+ mvderwin(times, 2-COMPACT, 0);
+ mvderwin(body, 2-COMPACT, 6);
+ wresize(head, 1, cols);
+ wresize(times, rows-2-COMPACT, 5);
+ wresize(body, rows-2-COMPACT, cols-6);
}
/* Day draw */
const char *dstr = day_to_string(day_of_week(YEAR, MONTH, DAY));
/* Print Header */
- mvwprintw(head, 0, 0, "%s, %s %d", dstr, mstr, DAY+1);
+ if (COMPACT) wattron(head, A_REVERSE | A_BOLD);
+ mvwprintw(head, 0, 0, "%s, %s %-*d", dstr, mstr, COLS, DAY+1);
mvwprintw(head, 0, COLS-10, "%d-%02d-%02d", YEAR, MONTH, DAY+1);
+ if (COMPACT) wattroff(head, A_REVERSE | A_BOLD);
/* Print times */
mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
}
/* Print lines */
- mvwhline(win, 1, 0, ACS_HLINE, COLS);
- mvwvline(win, 2, 5, ACS_VLINE, LINES-4);
+ if (!COMPACT)
+ mvwhline(win, 1, 0, ACS_HLINE, COLS);
+ mvwvline(win, 2-COMPACT, 5, ACS_VLINE, LINES-4+COMPACT+COMPACT);
}
/* Day run */
const int start = start_of_month(YEAR, MONTH);
const int days = days_in_month(YEAR, MONTH);
const int weeks = weeks_in_month(YEAR, MONTH);
+ const int hdr = COMPACT ? 3 : 4;
const float midpt = (float)COLS/2.0 - (strlen(name) + 1 + 4)/2.0;
const float hstep = (float)(COLS-1)/7.0;
- const float vstep = (float)(LINES-6)/weeks;
+ const float vstep = (float)(LINES-2-hdr+COMPACT)/weeks;
/* Print Header */
+ if (COMPACT) wattron(win, A_REVERSE | A_BOLD);
+ if (COMPACT) mvwhline(win, 0, 0, ' ' | A_REVERSE | A_BOLD, COLS);
+ if (COMPACT) mvwhline(win, 1, 0, ' ' | A_REVERSE | A_BOLD, COLS);
mvwprintw(win, 0, midpt, "%s %d", name, YEAR);
for (int d = 0; d < 7; d++) {
const char *str = hstep >= 10 ? day_to_string(d+SUN) : day_to_str(d+SUN);
mvwprintw(win, 1, ROUND(1+d*hstep), "%s", str);
}
- mvwhline(win, 2, 0, ACS_HLINE, COLS);
+ if (COMPACT) wattroff(win, A_REVERSE | A_BOLD);
+ if (!COMPACT) mvwhline(win, 2, 0, ACS_HLINE, COLS);
/* Print days */
for (int d = 0; d < days; d++) {
int row = (start + d) / 7;
int col = (start + d) % 7;
if (d == DAY) wattron(win, A_BOLD);
- mvwprintw(win, ROUND(4+row*vstep), ROUND(1+col*hstep), "%d", d+1);
+ mvwprintw(win, ROUND(hdr+row*vstep), ROUND(1+col*hstep), "%d", d+1);
if (d == DAY) wattroff(win, A_BOLD);
}
/* Print events */
event_t *event = EVENTS;
for (int d = 0; d < days; d++) {
- int y = ROUND(4+(((start + d) / 7) )*vstep);
- int e = ROUND(4+(((start + d) / 7)+1)*vstep)-2;
- int x = ROUND(1+(((start + d) % 7) )*hstep)+3;
- int w = ROUND(1+(((start + d) % 7)+1)*hstep)-x-1;
+ int y = ROUND(hdr+(((start + d) / 7) )*vstep);
+ int e = ROUND(hdr+(((start + d) / 7)+1)*vstep)-2;
+ int x = ROUND(1 +(((start + d) % 7) )*hstep)+3;
+ int w = ROUND(1 +(((start + d) % 7)+1)*hstep)-x-1;
while (event && before(&event->start, YEAR, MONTH, d, 24, 0)) {
if (!before(&event->start, YEAR, MONTH, d, 0, 0)){
if (y == e) mvwhline(win, y, x-3, ACS_DARROW, 2);
/* Print lines */
for (int w = 1; w < weeks; w++)
- mvwhline(win, ROUND(3+w*vstep), 1, ACS_HLINE, COLS-2);
+ mvwhline(win, ROUND(hdr-1+w*vstep), 1, ACS_HLINE, COLS-2);
for (int d = 1; d < 7; d++) {
int top = d >= start ? 0 : 1;
int bot = d <= (start+days-1)%7+1 ? weeks : weeks-1;
- mvwvline(win, ROUND(4+top*vstep), ROUND(d*hstep),
+ mvwvline(win, ROUND(hdr+top*vstep), ROUND(d*hstep),
ACS_VLINE, (bot-top)*vstep);
for (int w = 1; w < weeks; w++) {
int chr = w == top ? ACS_TTEE :
w == bot ? ACS_BTEE : ACS_PLUS;
- mvwaddch(win, ROUND(3+w*vstep), ROUND(d*hstep), chr);
+ mvwaddch(win, ROUND(hdr-1+w*vstep), ROUND(d*hstep), chr);
}
}
int row = (start+DAY) / 7;
int l = ROUND((col+0)*hstep);
int r = ROUND((col+1)*hstep);
- int t = ROUND((row+0)*vstep+3);
- int b = ROUND((row+1)*vstep+3);
+ int t = ROUND((row+0)*vstep+hdr-1);
+ int b = ROUND((row+1)*vstep+hdr-1);
mvwvline_set(win, t, l, WACS_T_VLINE, b-t);
mvwvline_set(win, t, r, WACS_T_VLINE, b-t);
mvwhline_set(win, t, l, WACS_T_HLINE, r-l);
/* Week size */
void week_size(int rows, int cols)
{
- wresize(head, 2, cols );
- wresize(times, rows-3, 5);
- wresize(body, rows-3, cols-6);
+ int hdr = 3-COMPACT;
+ wresize(head, 2, cols );
+ wresize(times, rows-hdr, 5);
+ wresize(body, rows-hdr, cols-6);
+ mvderwin(times, hdr, 0);
+ mvderwin(body, hdr, 6);
}
/* Week draw */
void week_draw(void)
{
int x = 6;
- int y = 3;
+ int y = 3 - COMPACT;
const float hstep = (float)(COLS-x)/7.0;
/* Get start of week */
int shift = day_of_week(year, month, day);
add_days(&year, &month, &day, -shift);
+ /* For today */
+ int l = x+ROUND((shift+0)*hstep)-1;
+ int r = x+ROUND((shift+1)*hstep)-1;
+
/* Print Header */
- mvwprintw(head, 0, 0, "%s", month_to_str(MONTH));
- mvwprintw(head, 1, 0, "%04d", YEAR);
+ int rev = COMPACT ? A_REVERSE | A_BOLD : 0;
+ wattron(head, rev);
+ mvwprintw(head, 0, 0, "%-*s", COLS, month_to_str(MONTH));
+ mvwprintw(head, 1, 0, "%-0*d", COLS, YEAR);
+ wattroff(head, rev);
+ mvwhline(head, 0, l+1, ' ', r-l-1);
+ mvwhline(head, 1, l+1, ' ', r-l-1);
+ wattron(head, rev);
for (int d = 0; d < 7; d++) {
const char *str = hstep >= 10 ? day_to_string(d) : day_to_str(d);
- if (d == shift) wattron(head, A_BOLD);
+ if (d == shift) wattrset(head, A_BOLD);
mvwprintw(head, 0, x+ROUND(d*hstep), "%s", str);
mvwprintw(head, 1, x+ROUND(d*hstep), "%02d/%02d", month+1, day+1);
- if (d == shift) wattroff(head, A_BOLD);
+ if (d == shift) wattrset(head, rev);
add_days(&year, &month, &day, 1);
}
+ wattroff(head, rev);
/* Print times */
mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
}
/* Print lines */
- mvwhline(win, y-1, 0, ACS_HLINE, COLS);
+ if (!COMPACT)
+ mvwhline(win, y-1, 0, ACS_HLINE, COLS);
for (int d = 0; d < 7; d++)
- mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2);
-
+ mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2+COMPACT);
/* Draw today */
- int l = x+ROUND((shift+0)*hstep)-1;
- int r = x+ROUND((shift+1)*hstep)-1;
- mvwhline (win, y-1, l, ACS_BLOCK, r-l+1);
+ if (!COMPACT)
+ mvwhline(win, y-1, l, ACS_BLOCK, r-l+1);
mvwvline_set(win, y, l, WACS_T_VLINE, LINES-y-2);
mvwvline_set(win, y, r, WACS_T_VLINE, LINES-y-2);
for (int h = (line+3)/4; h < 24; h++) {
int sum = h[0]+h[1]+h[2]+h[3];
/* Print Header */
+ if (COMPACT) wattron(win, A_REVERSE | A_BOLD);
+ if (COMPACT) mvwhline(win, y, 0, A_REVERSE | A_BOLD, COLS);
mvwprintw(win, y++, COLS/2-2, "%d", YEAR);
+ if (COMPACT) wattroff(win, A_REVERSE | A_BOLD);
/* Print Months */
for (int m = 0; m < 12; m++) {