]> Pileus Git - lackey/blobdiff - views/month.c
Add compact mode and view config data
[lackey] / views / month.c
index cbf611088a302f3a1b062386258fb4645695ac0b..c84fe94c5a980fdacd4a5e77927fa5db27e46efd 100644 (file)
@@ -46,34 +46,39 @@ void month_draw(void)
        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);
@@ -86,16 +91,16 @@ void month_draw(void)
 
        /* 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);
                }
        }
 
@@ -104,8 +109,8 @@ void month_draw(void)
        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);