From 4bd8717d8087f77926c91fb52250bd8ec533af1a Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 18 Jan 2016 18:09:32 +0100 Subject: Hide "0." prefix of todo items with undefined priority In the todo panel, all uncompleted items are currently prefixed with their priorities. Drop this prefix from items with priority 0, i.e. undefined priority. Signed-off-by: Lukas Fleischer --- src/ui-todo.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ui-todo.c b/src/ui-todo.c index 971c69d..da5ec3e 100644 --- a/src/ui-todo.c +++ b/src/ui-todo.c @@ -157,9 +157,10 @@ void ui_todo_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) { llist_item_t *i = *((llist_item_t **)cb_data); struct todo *todo = LLIST_TS_GET_DATA(i); - int mark[2]; - int width = lb_todo.sw.w; + char mark[] = { 0, 0, 0, 0 }; + int width = lb_todo.sw.w - 2; char buf[width * UTF8_MAXLEN]; + char *mesg; int j; if (ui_todo_view == TODO_HIDE_COMPLETED_VIEW) { @@ -170,8 +171,20 @@ void ui_todo_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) } } - mark[0] = todo->completed ? 'X' : '0' + todo->id; - mark[1] = todo->note ? '>' : '.'; + mark[0] = todo->completed ? 'X' : (todo->id > 0 ? '0' + todo->id : 0); + if (todo->note) { + if (mark[0] == '\0') { + mark[0] = '>'; + mark[1] = ' '; + } else { + mark[1] = '>'; + mark[2] = ' '; + } + } else if (mark[0] != '\0') { + mark[1] = '.'; + mark[2] = ' '; + } + width -= strlen(mark); hilt = hilt && (wins_slctd() == TOD); @@ -179,20 +192,27 @@ void ui_todo_draw(int n, WINDOW *win, int y, int hilt, void *cb_data) custom_apply_attr(win, ATTR_HIGHEST); if (utf8_strwidth(todo->mesg) < width) { - mvwprintw(win, y, 0, "%c%c %s", mark[0], mark[1], todo->mesg); + mesg = todo->mesg; } else { + width -= 3; for (j = 0; todo->mesg[j] && width > 0; j++) { if (!UTF8_ISCONT(todo->mesg[j])) width -= utf8_width(&todo->mesg[j]); buf[j] = todo->mesg[j]; } - if (j) - buf[j - 1] = 0; - else + if (j) { + buf[j - 1] = '.'; + buf[j] = '.'; + buf[j + 1] = '.'; + buf[j + 2] = '\0'; + } else { buf[0] = 0; - mvwprintw(win, y, 0, "%c%c %s...", mark[0], mark[1], buf); + } + mesg = buf; } + mvwprintw(win, y, 0, "%s%s", mark, mesg); + if (hilt) custom_remove_attr(win, ATTR_HIGHEST); -- cgit v1.2.3