]> Pileus Git - lackey/commitdiff
Add compact mode and view config data
authorAndy Spencer <andy753421@gmail.com>
Tue, 4 Jun 2013 04:31:53 +0000 (04:31 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 10 Jun 2013 04:53:24 +0000 (04:53 +0000)
src/util.c
src/view.c
src/view.h
views/day.c
views/month.c
views/week.c
views/year.c

index 131e9dea2e6261ccf4823030e4bde638a2bcff1d..420dbd56dd99b7279bcd0f21639859d2981c30e4 100644 (file)
@@ -25,6 +25,9 @@
 #include "view.h"
 #include "util.h"
 
+/* For testing */
+#pragma weak COMPACT
+
 /* Static data */
 static FILE *debug_fd = NULL;
 
@@ -50,14 +53,17 @@ static void message(FILE *output_fd, const char *prefix, const char *fmt, va_lis
        }
 
        /* 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();
        }
 }
 
index f55a7ddd9b05fc030c8ceb321ba57cab7b7ec5a8..6aa6f70126364436dfafcc68d53d2374a7de6f08 100644 (file)
@@ -36,7 +36,7 @@ typedef struct {
        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',    } },
@@ -50,7 +50,9 @@ view_t views[] = {
        { "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)
@@ -58,14 +60,15 @@ 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();
 }
 
@@ -174,9 +177,10 @@ void todo_line(WINDOW *win, todo_t *todo, int y, int x, int w, int full)
 /* 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);
                }
        }
@@ -185,11 +189,14 @@ void view_init(void)
 /* 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);
        }
 }
 
@@ -197,16 +204,16 @@ void view_resize(void)
 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;
@@ -215,6 +222,14 @@ int view_set(int num)
 /* 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;
@@ -228,7 +243,7 @@ int view_run(int key, mmask_t btn, int row, int col)
 
        /* 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)
@@ -236,7 +251,7 @@ int view_run(int key, mmask_t btn, int row, int col)
        }
 
        /* Shift windows */
-       int num   = active;
+       int num   = ACTIVE;
        int shift = key == KEY_RIGHT ? +1 :
                    key == KEY_LEFT  ? -1 : 0;
        while (shift) {
@@ -248,5 +263,5 @@ int view_run(int key, mmask_t btn, int row, int col)
        }
 
        /* Pass key to active view */
-       return views[active].run(key, btn, row, col);
+       return views[ACTIVE].run(key, btn, row, col);
 }
index e0aff1ef51b0b0dad9c5b56a6a0288196fcc2af0..845ca41daec0a9b81f562ac2fd22a4ecf8d56eca 100644 (file)
 #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);
index c8926e89204f8c9d30e509bf6410f0b5f5fdf5e8..672f855cf66eddb26764fda74bc1f47719985597 100644 (file)
@@ -92,7 +92,7 @@ static int get_col(event_t **list, int n, event_t *event, int *ncols)
 /* 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);
@@ -102,9 +102,11 @@ void day_init(WINDOW *_win)
 /* 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 */
@@ -114,8 +116,10 @@ void day_draw(void)
        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);
@@ -142,8 +146,9 @@ void day_draw(void)
        }
 
        /* 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 */
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);
index e94c9d819ca6302c8b4c07c7185fc6dbfa6fc7fa..414c35450b4c3a0e16e7f29b00b801665fe133c6 100644 (file)
@@ -45,16 +45,19 @@ void week_init(WINDOW *_win)
 /* 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 */
@@ -64,17 +67,28 @@ void week_draw(void)
        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);
@@ -100,15 +114,14 @@ void week_draw(void)
        }
 
        /* 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++) {
index 22a372dac54222bd1aa97c37e968d1b8f29b2dcd..a081484bdd12269401ac4d9142862fffd57c4c9f 100644 (file)
@@ -89,7 +89,10 @@ void year_draw(void)
        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++) {