]> Pileus Git - lackey/blobdiff - src/view.c
Fix a few off-by-one errors in date display
[lackey] / src / view.c
index fb97c517c555ed2fbc82364197397a08ff41295d..8341e97aa7433a428aefec70f5246b152937a837 100644 (file)
@@ -81,9 +81,12 @@ view_t *menu[] = {
        &spacer, &settings_view, &help_view
 };
 
-/* Global data */
+/* Config data */
 int COMPACT = 0;
 
+/* Global data */
+edit_t EDIT = EDIT_NONE;
+
 /* Local data */
 view_t *view   = &day_view;
 view_t *active = &day_view;
@@ -94,6 +97,9 @@ static void draw_header(void)
 {
        move(0, 0);
        attron(COLOR_PAIR(COLOR_TITLE));
+       clrtoeol();
+
+       /* Draw menu */
        for (int i = 0; i < N_ELEMENTS(menu); i++) {
                if (menu[i] == active)
                        attron(A_BOLD);
@@ -101,13 +107,21 @@ static void draw_header(void)
                if (menu[i] == active)
                        attroff(A_BOLD);
        }
-       clrtoeol();
+
+       /* Draw popup window */
        if (popup) {
+               printw("| ");
                attron(A_BOLD);
-               move(0, COLS-strlen(popup->title)-2);
                printw("[%s]", popup->title);
                attroff(A_BOLD);
        }
+
+       /* Draw date */
+       move(0, COLS-19);
+       printw("%04d-%02d-%02d %02d:%02d:%02d",
+                       NOW.year, NOW.month+1, NOW.day+1,
+                       NOW.hour, NOW.min,     NOW.sec);
+
        attroff(COLOR_PAIR(COLOR_TITLE));
        if (!COMPACT)
                mvhline(1, 0, ACS_HLINE, COLS);
@@ -195,7 +209,7 @@ void event_line(WINDOW *win, event_t *event, int y, int x, int w, int flags)
        mvwaddch(win, y, x++, ACS_BLOCK);
        if (color) wattroff(win, COLOR_PAIR(color));
 
-       if (flags & SHOW_ACTIVE)
+       if (flags & SHOW_ACTIVE && event == EVENT)
                wattron(win, A_REVERSE | A_BOLD);
        if (flags & SHOW_DETAILS) {
                if (all_day(&event->start, &event->end))
@@ -215,7 +229,7 @@ void event_line(WINDOW *win, event_t *event, int y, int x, int w, int flags)
        if (flags & SHOW_DETAILS && event->loc) {
                mvwprintw(win, y, x, " @ %s", event->loc);
        }
-       if (flags & SHOW_ACTIVE)
+       if (flags & SHOW_ACTIVE && event == EVENT)
                wattroff(win, A_REVERSE | A_BOLD);
 }
 
@@ -239,7 +253,7 @@ void todo_line(WINDOW *win, todo_t *todo, int y, int x, int w, int flags)
        x += 2;
 
        /* Set background */
-       if (flags & SHOW_ACTIVE)
+       if (flags & SHOW_ACTIVE && todo == TODO)
                wattron(win, A_REVERSE | A_BOLD);
        mvwhline(win, y, x, ' ', COLS-x);
 
@@ -264,7 +278,7 @@ void todo_line(WINDOW *win, todo_t *todo, int y, int x, int w, int flags)
        mvwprintw(win, y, x, "%s", desc);
 
        /* Reset flags */
-       if (flags & SHOW_ACTIVE)
+       if (flags & SHOW_ACTIVE && todo == TODO)
                wattroff(win, A_REVERSE | A_BOLD);
 }
 
@@ -320,6 +334,9 @@ void view_draw(void)
 /* View run */
 int view_run(int key, mmask_t btn, int row, int col)
 {
+       /* Refresh timestamp */
+       draw_header();
+
        /* Check for mouse events on the menu */
        if (key == KEY_MOUSE && row == 0) {
                int start = 1;
@@ -373,3 +390,10 @@ int view_run(int key, mmask_t btn, int row, int col)
        /* Pass key to active view */
        return view->run(key, btn, row, col);
 }
+
+/* View event */
+void view_edit(edit_t mode)
+{
+       EDIT = mode;
+       set_view(active, &edit_view);
+}