2 * Copyright (C) 2012-2013 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/>.
30 static int show_new = 1;
31 static int show_started = 1;
32 static int show_finished = 0;
34 /* Helper functions */
35 static int print_todos(WINDOW *win, int row, todo_t *todos, status_t low, status_t high)
38 for (todo_t *cur = todos; cur; cur = cur->next)
39 if (low <= cur->status && cur->status <= high)
40 todo_line(win, cur, row+n++, 4, COLS-4, 1);
44 static int print_group(WINDOW *win, int row, todo_t *todos,
45 int show, const char *label, status_t low, status_t high)
51 mvwprintw(win, row, 0, "%s", label);
52 wattroff(win, A_BOLD);
56 n = print_todos(win, row+1, todos, low, high);
60 mvwprintw(win, row+1, 4, "[hidden]");
62 mvwprintw(win, row+1, 4, "[no tasks]");
64 return row+1+MAX(n,1)+1;
68 void todo_init(WINDOW *_win)
74 void todo_size(int rows, int cols)
83 row = print_group(win, row, TODOS,
84 show_new, "New Tasks", NEW, NEW);
86 row = print_group(win, row, TODOS,
87 show_started, "Started Tasks", NEW+1, DONE-1);
89 row = print_group(win, row, TODOS,
90 show_finished, "Finished Tasks", DONE, DONE);
96 int todo_run(int key, mmask_t btn, int row, int col)
98 int scroll = 0, ref = 0;
101 case 'g': ref = 1; scroll = -line; break;
102 case 'G': ref = 1; scroll = rows; break;
103 case 'j': ref = 1; scroll = 1; break;
104 case 'k': ref = 1; scroll = -1; break;
105 case 'n': ref = 1; show_new ^= 1; break;
106 case 's': ref = 1; show_started ^= 1; break;
107 case 'f': ref = 1; show_finished ^= 1; break;
109 line = CLAMP(line+scroll, 0, rows-1);