#include "date.h"
/* Global data */
+date_t NOW;
date_t SEL;
/* Initialize */
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)
{
typedef int day_t;
typedef int hour_t;
typedef int min_t;
+typedef int sec_t;
typedef enum {
JAN = 0,
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);
keypad(stdscr, TRUE);
start_color();
curs_set(false);
+ timeout(100);
use_default_colors();
mousemask(ALL_MOUSE_EVENTS, NULL);
view_init();
/* Draw initial view */
+ date_sync();
view_draw();
/* Run */
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();
}
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);
}
{
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);
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);
/* 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;