PROG_SRC = main screen date event util
TEST = test
TEST_SRC = test date util
-VIEWS = day week month year todo notes settings help
+VIEWS = day week month year events todo settings help
CALS = dummy ical
# Targets
{ "Month", month_init, month_size, month_draw, month_run, {KEY_F(3), '3', } },
{ "Year", year_init, year_size, year_draw, year_run, {KEY_F(4), '4', } },
{ "|", NULL, NULL, NULL, NULL, { } },
- { "Todo", todo_init, todo_size, todo_draw, todo_run, {KEY_F(5), '5', } },
- { "Notes", notes_init, notes_size, notes_draw, notes_run, {KEY_F(6), '6', } },
+ { "Events", events_init, events_size, events_draw, events_run, {KEY_F(5), '5', } },
+ { "Todo", todo_init, todo_size, todo_draw, todo_run, {KEY_F(6), '6', } },
{ "|", NULL, NULL, NULL, NULL, { } },
{ "Settings", settings_init, settings_size, settings_draw, settings_run, {KEY_F(7), '7', } },
{ "Help", help_init, help_size, help_draw, help_run, {KEY_F(8), '8', '?'} },
};
-int active = 0;
+int active = 5;
/* Local functions */
void draw_header(void)
if (l<h && event->desc) mvwprintw(win, y+l++, x+1, "%.*s", w-2, event->desc);
}
-void event_line(WINDOW *win, event_t *event, int y, int x, int w)
+void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full)
{
int color = event->cat == NULL ? 0 :
!strcmp(event->cat, "class") ? COLOR_CLASS :
!strcmp(event->cat, "work") ? COLOR_WORK : COLOR_OTHER ;
if (color) wattron(win, COLOR_PAIR(color));
- mvwaddch(win, y, x+0, ACS_BLOCK);
+ mvwaddch(win, y, x++, ACS_BLOCK);
if (color) wattroff(win, COLOR_PAIR(color));
- mvwprintw(win, y, x+1, "%-*.*s", w-1, w-1, event->name);
+ if (full) {
+ mvwprintw(win, y, x, " %02d:%02d - ", event->start.hour, event->start.min);
+ x += 9;
+ }
+ if (event->name) {
+ const char *label = event->name ?: event->desc;
+ mvwprintw(win, y, x, "%-*.*s", w-1, w-1, label);
+ x += MIN(strlen(label), w-1);
+ }
+ if (full && event->loc) {
+ mvwprintw(win, y, x, " @ %s", event->loc);
+ }
}
/* Helper functions */
void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w);
-void event_line(WINDOW *win, event_t *event, int y, int x, int w);
+void event_line(WINDOW *win, event_t *event, int y, int x, int w, int full);
/* Screen functions */
void screen_init(void);
void week_init(WINDOW *win);
void month_init(WINDOW *win);
void year_init(WINDOW *win);
+void events_init(WINDOW *win);
void todo_init(WINDOW *win);
-void notes_init(WINDOW *win);
void settings_init(WINDOW *win);
void help_init(WINDOW *win);
void week_size(int,int);
void month_size(int,int);
void year_size(int,int);
+void events_size(int,int);
void todo_size(int,int);
-void notes_size(int,int);
void settings_size(int,int);
void help_size(int,int);
void week_draw(void);
void month_draw(void);
void year_draw(void);
+void events_draw(void);
void todo_draw(void);
-void notes_draw(void);
void settings_draw(void);
void help_draw(void);
int week_run(int,mmask_t,int,int);
int month_run(int,mmask_t,int,int);
int year_run(int,mmask_t,int,int);
+int events_run(int,mmask_t,int,int);
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);
--- /dev/null
+/*
+ * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define DEBUG
+
+#include <ncurses.h>
+
+#include <util.h>
+#include <date.h>
+#include <event.h>
+#include <screen.h>
+
+/* Static data */
+static WINDOW *win;
+static int line;
+static int rows;
+
+/* Events init */
+void events_init(WINDOW *_win)
+{
+ win = _win;
+}
+
+/* Events size */
+void events_size(int rows, int cols)
+{
+}
+
+/* Events draw */
+void events_draw(void)
+{
+ int days = 2*7;
+ int min = 12;
+
+ date_t start = {YEAR, MONTH, DAY, 0, 0};
+ date_t cur = {YEAR, MONTH, DAY-1, 0, 0};
+ date_t end = {YEAR, MONTH, DAY, 24, 0};
+ add_days(&end.year, &end.month, &end.day, days);
+
+ int row = 0;
+ int count = 0;
+ event_t *event = EVENTS;
+ while (event && (count < min || compare(&event->start, &end) < 0)) {
+ if (compare(&start, &event->start) <= 0) {
+ date_t next = event->start;
+ int newdate = cur.year != next.year ||
+ cur.month != next.month ||
+ cur.day != next.day ;
+ int newtime = cur.hour != next.hour ||
+ cur.min != next.min ;
+ if ((newdate || newtime) && row != 0)
+ row++;
+ if (newdate && row != 0)
+ row++;
+ if (newdate) {
+ wday_t wday = day_of_week(next.year, next.month, next.day);
+ wattron(win, A_UNDERLINE);
+ mvwprintw(win, row-line, 0, "%04d-%02d-%02d",
+ next.year, next.month+1, next.day+1);
+ mvwprintw(win, row-line, 13, "%s, %s %d",
+ day_to_string(wday), month_to_string(next.month), next.day);
+ wattroff(win, A_UNDERLINE);
+ row++;
+ }
+ event_line(win, event, row++-line, 3, COLS-2, 1);
+ if (event->name && event->desc)
+ mvwprintw(win, row++-line, 13, "%s", event->desc);
+ cur = next;
+ count += 1;
+ }
+ event = event->next;
+ }
+ rows = row;
+}
+
+/* Events run */
+int events_run(int key, mmask_t btn, int row, int col)
+{
+ int scroll = 0;
+ switch (key)
+ {
+ case 'g': scroll = -line; break;
+ case 'G': scroll = rows; break;
+ case 'j': scroll = 1; break;
+ case 'k': scroll = -1; break;
+ case 'd': scroll = LINES/2; break;
+ case 'u': scroll = -LINES/2; break;
+ case 'D': scroll = LINES; break;
+ case 'U': scroll = -LINES; break;
+ }
+ line = CLAMP(line+scroll, 0, rows-1);
+ if (scroll) {
+ werase(win);
+ events_draw();
+ wrefresh(win);
+ }
+ return 0;
+}
void help_draw(void)
{
mvwprintw(win, 0, 1, "%s\n", "help");
- wrefresh(win);
}
/* Help run */
while (event && before(&event->start, YEAR, MONTH, d, 24, 0)) {
if (!before(&event->start, YEAR, MONTH, d, 0, 0)){
if (y == e) mvwhline(win, y, x-3, ACS_DARROW, 2);
- if (y <= e) event_line(win, event, y, x, w);
+ if (y <= e) event_line(win, event, y, x, w, 0);
y++;
}
event = event->next;
+++ /dev/null
-/*
- * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <ncurses.h>
-
-/* Static data */
-static WINDOW *win;
-
-/* Notes init */
-void notes_init(WINDOW *_win)
-{
- win = _win;
-}
-
-/* Notes size */
-void notes_size(int rows, int cols)
-{
-}
-
-/* Notes draw */
-void notes_draw(void)
-{
- mvwprintw(win, 0, 1, "%s\n", "notes");
- wrefresh(win);
-}
-
-/* Notes run */
-int notes_run(int key, mmask_t btn, int row, int col)
-{
- return 0;
-}
void settings_draw(void)
{
mvwprintw(win, 0, 1, "%s\n", "settings");
- wrefresh(win);
}
/* Settings run */
void todo_draw(void)
{
mvwprintw(win, 0, 1, "%s\n", "todo");
- wrefresh(win);
}
/* Todo run */