]> Pileus Git - lackey/commitdiff
Display current time at the top right
authorAndy Spencer <andy753421@gmail.com>
Sun, 16 Jun 2013 23:24:05 +0000 (23:24 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 16 Jun 2013 23:24:05 +0000 (23:24 +0000)
src/date.c
src/date.h
src/main.c
src/view.c

index 9bcf81663906629c95bbf32890ae13026c05946e..5714f52a578a4b2c8f7c4ba7422bb398c5c81c10 100644 (file)
@@ -23,6 +23,7 @@
 #include "date.h"
 
 /* Global data */
+date_t  NOW;
 date_t  SEL;
 
 /* Initialize */
@@ -36,6 +37,19 @@ void date_init(void)
        SEL.day   = tm->tm_mday-1;
 }
 
+void date_sync(void)
+{
+       time_t     sec = time(NULL);
+       struct tm *tm  = localtime(&sec);
+
+       NOW.year  = tm->tm_year+1900;
+       NOW.month = tm->tm_mon;
+       NOW.day   = tm->tm_mday-1;
+       NOW.hour  = tm->tm_hour;
+       NOW.min   = tm->tm_min;
+       NOW.sec   = tm->tm_sec;
+}
+
 /* Time functions */
 int is_leap_year(year_t year)
 {
index a04d0dead46ce1be5835f173a9e378fd726e171d..600f26283509c704ccb9e1ecf4f846d33e6637ef 100644 (file)
@@ -22,6 +22,7 @@ typedef int year_t;
 typedef int day_t;
 typedef int hour_t;
 typedef int min_t;
+typedef int sec_t;
 
 typedef enum {
        JAN =  0,
@@ -54,13 +55,16 @@ typedef struct {
        day_t   day;
        hour_t  hour;
        min_t   min;
+       sec_t   sec;
 } date_t;
 
 /* Global data */
+extern date_t NOW; // current wall clock time, refreshed at 10 Hz
 extern date_t SEL; // date and time the user is looking at
 
 /* Initialize */
 void date_init(void);
+void date_sync(void);
 
 /* Time functions */
 int is_leap_year(year_t year);
index fdcfbd8dd637ed0bce733eb58b4d4f06d0e5505e..7d8d517d5f9772a9d0179563bda550b50e7d5ba2 100644 (file)
@@ -60,6 +60,7 @@ int main(int argc, char **argv)
        keypad(stdscr, TRUE);
        start_color();
        curs_set(false);
+       timeout(100);
        use_default_colors();
        mousemask(ALL_MOUSE_EVENTS, NULL);
 
@@ -86,6 +87,7 @@ int main(int argc, char **argv)
        view_init();
 
        /* Draw initial view */
+       date_sync();
        view_draw();
 
        /* Run */
@@ -93,14 +95,13 @@ int main(int argc, char **argv)
                MEVENT btn;
                conf_sync();
                int chr = getch();
+               date_sync();
                if (chr == 'q')
                        break;
                if (chr == KEY_MOUSE)
                        if (getmouse(&btn) != OK)
                                continue;
                switch (chr) {
-                       case ERR:
-                               continue;
                        case KEY_RESIZE:
                                endwin();
                                refresh();
@@ -116,6 +117,8 @@ int main(int argc, char **argv)
                }
                if (view_run(chr, btn.bstate, btn.y, btn.x))
                        continue;
+               if (chr == ERR) // timeout
+                       continue;
                debug("main: Unhandled key - Dec %3d,  Hex %02x,  Oct %03o,  Chr <%c>",
                                chr, chr, chr, chr);
        }
index fb97c517c555ed2fbc82364197397a08ff41295d..35278494fed12cea0276c6dc04931285f36b9f8c 100644 (file)
@@ -94,6 +94,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 +104,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, NOW.day,
+                       NOW.hour, NOW.min,   NOW.sec);
+
        attroff(COLOR_PAIR(COLOR_TITLE));
        if (!COMPACT)
                mvhline(1, 0, ACS_HLINE, COLS);
@@ -320,6 +331,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;