]> Pileus Git - lackey/commitdiff
Make month view interactive
authorAndy Spencer <andy753421@gmail.com>
Sat, 6 Oct 2012 08:01:38 +0000 (08:01 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 6 Oct 2012 08:01:38 +0000 (08:01 +0000)
src/main.c
src/main.h
src/screen.c
src/screen.h
src/util.c
src/util.h
view/month.c

index d1a1fce62dd51e89f00c37766e6343109c69bc54..20bea55e766185ee350f0ab0e1982231b4ab5b74 100644 (file)
 #include <stdlib.h>
 #include <signal.h>
 #include <time.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <time.h>
+#include <locale.h>
 #include <ncurses.h>
 
 #include "main.h"
 #include "screen.h"
 
 /* Debugging */
 #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;
 
 /* Static data */
 static FILE *debug_fd = NULL;
@@ -78,6 +79,7 @@ int main(int argc, char **argv)
        DAY   = tm->tm_mday-1;
 
        /* Curses setup */
        DAY   = tm->tm_mday-1;
 
        /* Curses setup */
+       setlocale(LC_ALL, "");
        initscr();
        cbreak();
        noecho();
        initscr();
        cbreak();
        noecho();
@@ -108,9 +110,8 @@ int main(int argc, char **argv)
                                screen_resize();
                                screen_draw();
                                continue;
                                screen_resize();
                                screen_draw();
                                continue;
-                       case 'L':
+                       case '\14':
                                clear();
                                clear();
-                       case 'l':
                        case '\7':
                                screen_draw();
                                continue;
                        case '\7':
                                screen_draw();
                                continue;
index dd7c3fbd1d2ab8ef3d6d023c76bd8d55ac7e143b..d1d4511e82f89094282c788a8929876e1f50bf4d 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * 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
 
 #define COLOR_TITLE 1
 #define COLOR_ERROR 2
 
+#include "util.h"
+
 /* Debugging */
 /* 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, ...);
 
 /* Debug functions */
 int debug(char *fmt, ...);
+
+#endif
index e10a54d8ec9b9b6b432bcce2a37b084a88a06f7f..feb23c6c7bd213dbc2429942ca2aa158545e4ace 100644 (file)
@@ -33,16 +33,16 @@ typedef struct {
 
 /* Data */
 view_t views[] = {
 
 /* 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;
 };
 
 int active = 0;
index 0235c8274c846f38256cbb0cd6674298a21e2a48..f5b86713e81ad7f3dc195eabbad05a1fbacd811a 100644 (file)
@@ -15,6 +15,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * 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);
 /* Screen functions */
 void screen_init(void);
 void screen_resize(void);
@@ -50,3 +53,5 @@ int todo_run(int,mmask_t,int,int);
 int notes_run(int,mmask_t,int,int);
 int settings_run(int,mmask_t,int,int);
 int help_run(int,mmask_t,int,int);
 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
index 688cc949813bfd6ba3667db026d17fadfbb6b8e1..e40fa8e2c6c747dfb575f4ec84cc93004f96e47a 100644 (file)
@@ -83,6 +83,13 @@ void add_days(year_t *year, month_t *month, day_t *day, int days)
        *day   = tm->tm_mday-1;
 }
 
        *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)
 {
 /* Debug functions */
 const char *month_to_str(month_t month)
 {
@@ -123,14 +130,15 @@ const char *day_to_string(wday_t day)
 /* Test functions */
 void test_time(void)
 {
 /* 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++) {
        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");
        }
 }
                printf("\n");
        }
 }
index e814dfdcd6e4b8d2a4fb2523791989b161300ad7..f073205352529f7cf0977a27261c8ea9aad87e65 100644 (file)
@@ -15,6 +15,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * 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))
 /* Macros */
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 #define MAX(a,b) ((a) > (b) ? (a) : (b))
@@ -59,6 +62,7 @@ wday_t day_of_week(year_t year, month_t month, day_t day);
 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);
 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);
 
 /* Time to string functions */
 const char *month_to_str(month_t month);
@@ -69,3 +73,5 @@ const char *day_to_string(wday_t day);
 
 /* Tests */
 void test_time(void);
 
 /* Tests */
 void test_time(void);
+
+#endif
index fb2be064a2612e38a39ffd8a555840aec161f86b..f93bc74a183f257dfdb242caf021259c5035a17d 100644 (file)
@@ -15,6 +15,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define _XOPEN_SOURCE_EXTENDED
+
 #include <string.h>
 #include <ncurses.h>
 
 #include <string.h>
 #include <ncurses.h>
 
@@ -41,6 +43,9 @@ void month_draw(void)
        const float hstep = (float)COLS/7.0;
        const float vstep = (float)(LINES-4)/weeks;
 
        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++) {
        /* Print Header */
        mvwprintw(win, 0, midpt, "%s %d", name, YEAR);
        for (int d = 0; d < 7; d++) {
@@ -70,10 +75,42 @@ void month_draw(void)
                        mvwaddch(win, ROUND(2+w*vstep), ROUND(d*hstep-1), chr);
                }
        }
                        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)
 {
 }
 
 /* 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;
 }
        return 0;
 }