aboutsummaryrefslogtreecommitdiffstats
path: root/src/todo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/todo.c')
-rw-r--r--src/todo.c130
1 files changed, 78 insertions, 52 deletions
diff --git a/src/todo.c b/src/todo.c
index 8000197..b89d595 100644
--- a/src/todo.c
+++ b/src/todo.c
@@ -61,29 +61,29 @@ todo_hilt_set (int highlighted)
}
void
-todo_hilt_decrease (void)
+todo_hilt_decrease (int n)
{
- hilt--;
+ hilt -= n;
}
void
-todo_hilt_increase (void)
+todo_hilt_increase (int n)
{
- hilt++;
+ hilt += n;
}
/* Return which todo is highlighted. */
int
todo_hilt (void)
{
- return (hilt);
+ return hilt;
}
/* Return the number of todos. */
int
todo_nb (void)
{
- return (todos);
+ return todos;
}
/* Set the number of todos. */
@@ -101,15 +101,15 @@ todo_set_first (int nb)
}
void
-todo_first_increase (void)
+todo_first_increase (int n)
{
- first++;
+ first += n;
}
void
-todo_first_decrease (void)
+todo_first_decrease (int n)
{
- first--;
+ first -= n;
}
/*
@@ -119,14 +119,14 @@ todo_first_decrease (void)
int
todo_hilt_pos (void)
{
- return (hilt - first);
+ return hilt - first;
}
/* Return the last visited todo. */
char *
todo_saved_mesg (void)
{
- return (msgsav);
+ return msgsav;
}
/* Request user to enter a new todo item. */
@@ -162,7 +162,7 @@ todo_cmp_id (struct todo *a, struct todo *b)
int abs_a = abs (a->id);
int abs_b = abs (b->id);
- return (abs_a < abs_b ? -1 : (abs_a == abs_b ? 0 : 1));
+ return abs_a < abs_b ? -1 : (abs_a == abs_b ? 0 : 1);
}
/*
@@ -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)
+ fprintf (f, "[%d]>%s %s\n", todo->id, todo->note, todo->mesg);
+ else
+ 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)
@@ -195,12 +204,12 @@ todo_delete_note_bynum (unsigned num)
if (!todo->note)
EXIT (_("no note attached"));
- erase_note (&todo->note, ERASE_FORCE_ONLY_NOTE);
+ erase_note (&todo->note);
}
/* Delete an item from the todo linked list. */
static void
-todo_delete_bynum (unsigned num, enum eraseflg flag)
+todo_delete_bynum (unsigned num)
{
llist_item_t *i = LLIST_NTH (&todolist, num);
@@ -210,7 +219,7 @@ todo_delete_bynum (unsigned num, enum eraseflg flag)
LLIST_REMOVE (&todolist, i);
mem_free (todo->mesg);
- erase_note (&todo->note, flag);
+ erase_note (&todo->note);
mem_free (todo);
}
@@ -279,7 +288,7 @@ todo_delete (struct conf *conf)
switch (answer)
{
case 't':
- todo_delete_bynum (hilt - 1, ERASE_FORCE);
+ todo_delete_bynum (hilt - 1);
todos--;
if (hilt > 1)
hilt--;
@@ -325,14 +334,14 @@ todo_chg_priority (int action)
struct todo *backup;
char backup_mesg[BUFSIZ];
int backup_id;
- char backup_note[NOTESIZ + 1];
+ char backup_note[MAX_NOTESIZ + 1];
int do_chg = 1;
backup = todo_get_item (hilt);
- (void)strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
+ strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
backup_id = backup->id;
if (backup->note)
- (void)strncpy (backup_note, backup->note, NOTESIZ + 1);
+ strncpy (backup_note, backup->note, MAX_NOTESIZ + 1);
else
backup_note[0] = '\0';
switch (action)
@@ -349,7 +358,7 @@ todo_chg_priority (int action)
}
if (do_chg)
{
- todo_delete_bynum (hilt - 1, ERASE_FORCE_KEEP_NOTE);
+ todo_delete_bynum (hilt - 1);
backup = todo_add (backup_mesg, backup_id, backup_note);
hilt = todo_get_position (backup);
}
@@ -369,28 +378,37 @@ 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) ? '>' : '.';
if (prio > 0)
snprintf (priostr, sizeof priostr, "%d", prio);
else
- snprintf (priostr, sizeof priostr, "X");
+ strncpy (priostr, "X", sizeof priostr);
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)
@@ -419,7 +437,7 @@ todo_update_panel (int which_pan)
struct todo *todo = LLIST_TS_GET_DATA (i);
num_todo++;
t_realpos = num_todo - first;
- incolor = num_todo - hilt;
+ incolor = (which_pan == TOD) ? num_todo - hilt : num_todo;
if (incolor == 0)
msgsav = todo->mesg;
if (t_realpos >= 0 && t_realpos < max_items)
@@ -453,44 +471,52 @@ todo_update_panel (int which_pan)
void
todo_edit_note (char *editor)
{
- struct todo *i;
- char fullname[BUFSIZ];
- char *filename;
-
- i = todo_get_item (hilt);
- if (i->note == NULL)
- {
- if ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
- i->note = filename;
- else
- return;
- }
- (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
- wins_launch_external (fullname, editor);
-
- if (io_file_is_empty (fullname) > 0)
- erase_note (&i->note, ERASE_FORCE);
+ struct todo *i = todo_get_item (hilt);
+ edit_note (&i->note, editor);
}
/* View a note previously attached to a todo */
void
todo_view_note (char *pager)
{
- struct todo *i;
- char fullname[BUFSIZ];
+ struct todo *i = todo_get_item (hilt);
+ view_note (i->note, pager);
+}
- i = todo_get_item (hilt);
- if (i->note == NULL)
+/* 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;
- (void)snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
- wins_launch_external (fullname, pager);
+
+ 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)
{
mem_free (todo->mesg);
- erase_note (&todo->note, ERASE_FORCE_KEEP_NOTE);
+ erase_note (&todo->note);
mem_free (todo);
}