2 * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
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.
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.
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/>.
18 #define _POSIX_C_SOURCE 1
34 static FILE *debug_fd = NULL;
36 /* Control-C handler, so we don't hose the therminal */
37 static void on_sigint(int signum)
44 static void on_sigwinch(int signum)
52 /* Debugging functions */
53 int debug(char *fmt, ...)
60 debug_fd = fopen("lackey.log", "w+");
62 /* Log to debug file */
64 vfprintf(debug_fd, "debug: ", ap);
65 rval = vfprintf(debug_fd, fmt, ap);
67 /* Log to status bar */
69 mvhline(LINES-2, 0, ACS_HLINE, COLS);
71 attron(COLOR_PAIR(COLOR_ERROR));
72 vwprintw(stdscr, fmt, ap);
73 attroff(COLOR_PAIR(COLOR_ERROR));
81 int main(int argc, char **argv)
85 sigemptyset(&act.sa_mask);
87 act.sa_handler = on_sigint;
88 sigaction(SIGINT, &act, NULL);
89 act.sa_handler = on_sigwinch;
90 sigaction(SIGWINCH, &act, NULL);
93 time_t sec = time(NULL);
94 struct tm *tm = localtime(&sec);
95 YEAR = tm->tm_year+1900;
103 keypad(stdscr, TRUE);
106 mousemask(ALL_MOUSE_EVENTS, NULL);
107 init_pair(COLOR_TITLE, COLOR_GREEN, COLOR_BLACK);
108 init_pair(COLOR_ERROR, COLOR_RED, COLOR_BLACK);
116 if (chr == KEY_MOUSE)
117 if (getmouse(&btn) != OK)
122 //debug("mouse xyz=%d,%d,%d id=%hd state=%lx\n",
123 // btn.x, btn.y, btn.z, btn.id, btn.bstate);
131 screen_run(chr, btn.bstate, btn.y, btn.x);
136 /* Cleanup, see also on_sigint */