diff options
Diffstat (limited to 'src/todo.c')
-rw-r--r-- | src/todo.c | 57 |
1 files changed, 52 insertions, 5 deletions
@@ -183,6 +183,15 @@ todo_add (char *mesg, int id, char *note) return todo; } +void +todo_write (struct todo *todo, FILE *f) +{ + if (todo->note) + (void)fprintf (f, "[%d]>%s %s\n", todo->id, todo->note, todo->mesg); + else + (void)fprintf (f, "[%d] %s\n", todo->id, todo->mesg); +} + /* Delete a note previously attached to a todo item. */ static void todo_delete_note_bynum (unsigned num) @@ -369,12 +378,13 @@ todo_edit_item (void) /* Display todo items in the corresponding panel. */ static void -display_todo_item (int incolor, char *msg, int prio, int note, int len, int y, +display_todo_item (int incolor, char *msg, int prio, int note, int width, int y, int x) { WINDOW *w; int ch_note; - char buf[len], priostr[2]; + char buf[width * UTF8_MAXLEN], priostr[2]; + int i; w = win[TOD].p; ch_note = (note) ? '>' : '.'; @@ -385,12 +395,20 @@ display_todo_item (int incolor, char *msg, int prio, int note, int len, int y, if (incolor == 0) custom_apply_attr (w, ATTR_HIGHEST); - if (strlen (msg) < len) + if (utf8_strwidth (msg) < width) mvwprintw (w, y, x, "%s%c %s", priostr, ch_note, msg); else { - (void)strncpy (buf, msg, len - 1); - buf[len - 1] = '\0'; + for (i = 0; msg[i] && width > 0; i++) + { + if (!UTF8_ISCONT (msg[i])) + width -= utf8_width (&msg[i]); + buf[i] = msg[i]; + } + if (i) + buf[i - 1] = 0; + else + buf[0] = 0; mvwprintw (w, y, x, "%s%c %s...", priostr, ch_note, buf); } if (incolor == 0) @@ -486,6 +504,35 @@ todo_view_note (char *pager) wins_launch_external (fullname, pager); } +/* Pipe a todo item to an external program. */ +void +todo_pipe_item (void) +{ + char cmd[BUFSIZ] = ""; + int pout; + int pid; + FILE *fpout; + struct todo *todo; + + status_mesg (_("Pipe item to external command:"), ""); + if (getstring (win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID) + return; + + wins_prepare_external (); + if ((pid = shell_exec (NULL, &pout, cmd))) + { + fpout = fdopen (pout, "w"); + + todo = todo_get_item (hilt); + todo_write (todo, fpout); + + fclose (fpout); + child_wait (NULL, &pout, pid); + press_any_key (); + } + wins_unprepare_external (); +} + void todo_free (struct todo *todo) { |