#include <stdlib.h>
#include <signal.h>
#include <time.h>
+#include <locale.h>
#include <ncurses.h>
#include "main.h"
#include "screen.h"
/* Debugging */
-int YEAR = 2012;
-int MONTH = 8;
-int DAY = 29;
+year_t YEAR = 2012;
+month_t MONTH = 8;
+day_t DAY = 29;
/* Static data */
static FILE *debug_fd = NULL;
DAY = tm->tm_mday-1;
/* Curses setup */
+ setlocale(LC_ALL, "");
initscr();
cbreak();
noecho();
screen_resize();
screen_draw();
continue;
- case 'L':
+ case '\14':
clear();
- case 'l':
case '\7':
screen_draw();
continue;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef MAIN_H
+#define MAIN_H
+
#define COLOR_TITLE 1
#define COLOR_ERROR 2
+#include "util.h"
+
/* Debugging */
-extern int YEAR;
-extern int MONTH;
-extern int DAY;
+extern year_t YEAR;
+extern month_t MONTH;
+extern day_t DAY;
/* Debug functions */
int debug(char *fmt, ...);
+
+#endif
/* Data */
view_t views[] = {
- { "Day", day_init, day_draw, day_run, {KEY_F(1), '1', 'd', } },
- { "Week", week_init, week_draw, week_run, {KEY_F(2), '2', 'w', } },
- { "Month", month_init, month_draw, month_run, {KEY_F(3), '3', 'm', } },
- { "Year", year_init, year_draw, year_run, {KEY_F(4), '4', 'y', } },
- { "|", NULL, NULL, NULL, { } },
- { "Todo", todo_init, todo_draw, todo_run, {KEY_F(5), '5', 't', } },
- { "Notes", notes_init, notes_draw, notes_run, {KEY_F(6), '6', 'n', } },
- { "|", NULL, NULL, NULL, { } },
- { "Settings", settings_init, settings_draw, settings_run, {KEY_F(7), '7', 's', } },
- { "Help", help_init, help_draw, help_run, {KEY_F(8), '8', 'h', '?'} },
+ { "Day", day_init, day_draw, day_run, {KEY_F(1), '1', } },
+ { "Week", week_init, week_draw, week_run, {KEY_F(2), '2', } },
+ { "Month", month_init, month_draw, month_run, {KEY_F(3), '3', } },
+ { "Year", year_init, year_draw, year_run, {KEY_F(4), '4', } },
+ { "|", NULL, NULL, NULL, { } },
+ { "Todo", todo_init, todo_draw, todo_run, {KEY_F(5), '5', } },
+ { "Notes", notes_init, notes_draw, notes_run, {KEY_F(6), '6', } },
+ { "|", NULL, NULL, NULL, { } },
+ { "Settings", settings_init, settings_draw, settings_run, {KEY_F(7), '7', } },
+ { "Help", help_init, help_draw, help_run, {KEY_F(8), '8', '?'} },
};
int active = 0;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef SCREEN_H
+#define SCREEN_H
+
/* Screen functions */
void screen_init(void);
void screen_resize(void);
int notes_run(int,mmask_t,int,int);
int settings_run(int,mmask_t,int,int);
int help_run(int,mmask_t,int,int);
+
+#endif
*day = tm->tm_mday-1;
}
+void add_months(year_t *year, month_t *month, int months)
+{
+ int total = *year*12 + *month + months;
+ *year = total / 12;
+ *month = total % 12;
+}
+
/* Debug functions */
const char *month_to_str(month_t month)
{
/* Test functions */
void test_time(void)
{
- printf("Year Month Start Weeks Days\n");
+ printf("Info\n");
+ printf(" Year Month Start Weeks Days\n");
for (int y = 2012; y <= 2012; y++)
for (int m = JAN; m <= DEC; m++) {
- printf("%-5d", y);
- printf("%-10s", month_to_string(m));
- printf("%-6s", day_to_str(start_of_month(y,m)));
- printf("%-6d", weeks_in_month(y,m));
- printf("%-2d", days_in_month(y,m));
+ printf(" %-5d", y);
+ printf(" %-10s", month_to_string(m));
+ printf(" %-6s", day_to_str(start_of_month(y,m)));
+ printf(" %-6d", weeks_in_month(y,m));
+ printf(" %-2d", days_in_month(y,m));
printf("\n");
}
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef UTIL_H
+#define UTIL_H
+
/* Macros */
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
wday_t start_of_month(year_t year, month_t month);
day_t start_of_week(year_t year, month_t month, day_t day);
void add_days(year_t *year, month_t *month, day_t *day, int days);
+void add_months(year_t *year, month_t *month, int months);
/* Time to string functions */
const char *month_to_str(month_t month);
/* Tests */
void test_time(void);
+
+#endif
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define _XOPEN_SOURCE_EXTENDED
+
#include <string.h>
#include <ncurses.h>
const float hstep = (float)COLS/7.0;
const float vstep = (float)(LINES-4)/weeks;
+ /* Clear */
+ werase(win);
+
/* Print Header */
mvwprintw(win, 0, midpt, "%s %d", name, YEAR);
for (int d = 0; d < 7; d++) {
mvwaddch(win, ROUND(2+w*vstep), ROUND(d*hstep-1), chr);
}
}
+
+ /* Draw today */
+ int col = day_of_week(YEAR, MONTH, DAY);
+ int row = (start+DAY) / 7;
+ int l = ROUND((col+0)*hstep-1);
+ int r = ROUND((col+1)*hstep-1);
+ int t = ROUND((row+0)*vstep+2);
+ int b = ROUND((row+1)*vstep+2);
+ 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);
+ mvwhline_set(win, b, l, WACS_T_HLINE, r-l);
+ mvwadd_wch(win, t, l, WACS_T_ULCORNER);
+ mvwadd_wch(win, t, r, WACS_T_URCORNER);
+ mvwadd_wch(win, b, l, WACS_T_LLCORNER);
+ mvwadd_wch(win, b, r, WACS_T_LRCORNER);
}
/* Month run */
int month_run(int key, mmask_t btn, int row, int col)
{
+ int days = 0, months = 0;
+ switch (key)
+ {
+ case 'h': days = -1; break;
+ case 'j': days = 7; break;
+ case 'k': days = -7; break;
+ case 'l': days = 1; break;
+ case 'i': months = -1; break;
+ case 'o': months = 1; break;
+ }
+ if (days || months) {
+ add_days(&YEAR, &MONTH, &DAY, days);
+ add_months(&YEAR, &MONTH, months);
+ month_draw();
+ wrefresh(win);
+ }
return 0;
}