]> Pileus Git - lackey/blob - src/main.c
Cleanup headers and whitespace
[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 "cal.h"
26 #include "view.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_NEW,   COLOR_RED,     -1);
56         init_pair(COLOR_WIP,   COLOR_YELLOW,  -1);
57         init_pair(COLOR_DONE,  COLOR_GREEN,   -1);
58
59         init_pair(COLOR_CLASS, COLOR_BLUE,    -1);
60         init_pair(COLOR_EC,    COLOR_GREEN,   -1);
61         init_pair(COLOR_WORK,  COLOR_MAGENTA, -1);
62         init_pair(COLOR_OTHER, COLOR_RED,     -1);
63
64         /* Initialize */
65         util_init();
66         date_init();
67         cal_init();
68         view_init();
69
70         /* Draw initial view */
71         view_draw();
72
73         /* Run */
74         while (1) {
75                 MEVENT btn;
76                 int chr = getch();
77                 if (chr == 'q')
78                         break;
79                 if (chr == KEY_MOUSE)
80                         if (getmouse(&btn) != OK)
81                                 continue;
82                 switch (chr) {
83                         case ERR:
84                                 continue;
85                         case KEY_RESIZE:
86                                 endwin();
87                                 refresh();
88                                 view_resize();
89                                 view_draw();
90                                 continue;
91                         case '\14':
92                                 clear();
93                         case '\7':
94                                 view_draw();
95                                 continue;
96                 }
97                 if (view_run(chr, btn.bstate, btn.y, btn.x))
98                         continue;
99                 debug("main: Unhandled key - Dec %3d,  Hex %02x,  Oct %03o,  Chr <%c>\n",
100                                 chr, chr, chr, chr);
101         }
102
103         /* Cleanup, see also on_sigint */
104         endwin();
105         return 0;
106 }