]> Pileus Git - lackey/blob - src/main.c
Add size function, update ical/week
[lackey] / src / main.c
1 /*
2  * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <stdlib.h>
19 #include <signal.h>
20 #include <locale.h>
21 #include <ncurses.h>
22
23 #include "util.h"
24 #include "date.h"
25 #include "event.h"
26 #include "screen.h"
27
28 /* Control-C handler, so we don't hose the therminal */
29 static void on_sigint(int signum)
30 {
31         endwin();
32         exit(0);
33 }
34
35 /* Main */
36 int main(int argc, char **argv)
37 {
38         /* Misc setup */
39         signal(SIGINT, on_sigint);
40
41         /* Setup Curses */
42         setlocale(LC_ALL, "");
43         initscr();
44         cbreak();
45         noecho();
46         keypad(stdscr, TRUE);
47         start_color();
48         curs_set(false);
49         use_default_colors();
50         mousemask(ALL_MOUSE_EVENTS, NULL);
51
52         init_pair(COLOR_TITLE, COLOR_GREEN,   -1);
53         init_pair(COLOR_ERROR, COLOR_RED,     -1);
54
55         init_pair(COLOR_CLASS, COLOR_BLUE,    -1);
56         init_pair(COLOR_EC,    COLOR_GREEN,   -1);
57         init_pair(COLOR_WORK,  COLOR_MAGENTA, -1);
58         init_pair(COLOR_OTHER, COLOR_RED,     -1);
59
60         /* Initialize */
61         util_init();
62         date_init();
63         event_init();
64         screen_init();
65
66         /* Draw initial screen */
67         screen_draw();
68
69         /* Run */
70         while (1) {
71                 MEVENT btn;
72                 int chr = getch();
73                 if (chr == 'q')
74                         break;
75                 if (chr == KEY_MOUSE)
76                         if (getmouse(&btn) != OK)
77                                 continue;
78                 switch (chr) {
79                         case ERR:
80                                 continue;
81                         case KEY_RESIZE:
82                                 endwin();
83                                 refresh();
84                                 screen_resize();
85                                 screen_draw();
86                                 continue;
87                         case '\14':
88                                 clear();
89                         case '\7':
90                                 screen_draw();
91                                 continue;
92                 }
93                 if (screen_run(chr, btn.bstate, btn.y, btn.x))
94                         continue;
95                 debug("main: Unhandled key - Dec %3d,  Hex %02x,  Oct %03o,  Chr <%c>\n",
96                                 chr, chr, chr, chr);
97         }
98
99         /* Cleanup, see also on_sigint */
100         endwin();
101         return 0;
102 }