X-Git-Url: http://pileus.org/git/?p=lackey;a=blobdiff_plain;f=views%2Ftodo.c;h=595db729151bedbd705f11d36aaae3afc78190be;hp=58c3b8b37bcb62d5ca5cf98fa50c50abd23fc3d4;hb=036dfbeb26c5d8b938231a8311f768e32c7cb2ed;hpb=b90716f36fac6e8c16dabd981cd47eeb9a8ec4f1 diff --git a/views/todo.c b/views/todo.c index 58c3b8b..595db72 100644 --- a/views/todo.c +++ b/views/todo.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Andy Spencer + * Copyright (C) 2012-2013 Andy Spencer * * 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 @@ -24,8 +24,15 @@ /* Static data */ static WINDOW *win; -static int line; -static int rows; + +static int line; // scroll offset +static int rows; // number of rows + +static int srow; // selected row +static int cursor; // index of the selected row +static int items; // number of items displayed +static int first; // cursor on first item in group +static int last; // cursor on last item in group static int show_new = 1; static int show_started = 1; @@ -34,10 +41,21 @@ static int show_finished = 0; /* Helper functions */ static int print_todos(WINDOW *win, int row, todo_t *todos, status_t low, status_t high) { - int n = 0; - for (todo_t *cur = todos; cur; cur = cur->next) - if (low <= cur->status && cur->status <= high) - todo_line(win, cur, row+n++, 4, COLS-4, 1); + int n = 0, found = 0; + for (todo_t *cur = todos; cur; cur = cur->next) { + if (low <= cur->status && cur->status <= high) { + if (found) + last = 0; + if (items++ == cursor) { + found = 1; + first = n == 0; + last = 1; + TODO = cur; + srow = row+n; + } + todo_line(win, cur, row+n++, 4, COLS-4, SHOW_DETAILS | SHOW_ACTIVE); + } + } return n; } @@ -47,8 +65,10 @@ static int print_group(WINDOW *win, int row, todo_t *todos, int n = 1; /* Label */ - wattron(win, A_BOLD); - mvwprintw(win, row, 0, "%s", label); + wattron(win, A_BOLD | A_UNDERLINE); + mvwprintw(win, row, 0, "%c", label[0]); + wattroff(win, A_UNDERLINE); + mvwprintw(win, row, 1, "%s", &label[1]); wattroff(win, A_BOLD); /* Todos */ @@ -80,6 +100,9 @@ void todo_draw(void) { int row = -line; + TODO = 0; + items = 0; + row = print_group(win, row, TODOS, show_new, "New Tasks", NEW, NEW); @@ -95,18 +118,38 @@ void todo_draw(void) /* Todo run */ int todo_run(int key, mmask_t btn, int row, int col) { - int scroll = 0, ref = 0; + int scroll = 0, move = 0, ref = 0; switch (key) { - case 'g': ref = 1; scroll = -line; break; - case 'G': ref = 1; scroll = rows; break; - case 'j': ref = 1; scroll = 1; break; - case 'k': ref = 1; scroll = -1; break; - case 'n': ref = 1; show_new ^= 1; break; - case 's': ref = 1; show_started ^= 1; break; - case 'f': ref = 1; show_finished ^= 1; break; + case 'g': ref = 1; scroll = -line; break; + case 'G': ref = 1; scroll = rows; break; + case '\005': ref = 1; scroll = 1; break; // ctrl-e + case '\031': ref = 1; scroll = -1; break; // ctrl-y + case 'j': ref = 1; move = 1; break; + case 'k': ref = 1; move = -1; break; + case 'n': ref = 1; show_new ^= 1; break; + case 's': ref = 1; show_started ^= 1; break; + case 'f': ref = 1; show_finished ^= 1; break; + case 'e': view_edit(EDIT_TODO); return 1; + case '\012': view_edit(EDIT_TODO); return 1; // enter } - line = CLAMP(line+scroll, 0, rows-1); + + /* Move more if we're on the edge of a group */ + int extra = 0; + if (move < 0 && first) extra = -2; + if (move > 0 && last) extra = 2; + + /* Scroll window when we move off screen */ + int next = line + srow + move + extra; + int ymax = getmaxy(win)-1; + while (next-line < 0) line--; + while (next-line > ymax) line++; + + /* Update line and cursor positions */ + line = CLAMP(line+scroll, 0, rows-1); + cursor = CLAMP(cursor+move, 0, items-1); + + /* Repaint */ if (ref) { werase(win); todo_draw();