Use backwards-compatible out format for queries

Print TODO items before appointments in query outputs and add an empty
line between the list of TODO items and the list of appointments. This
is how items were printed before the big parser refactoring.

Also, add a test to ensure we do not unintentionally change that format
in the future.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-08-06 15:48:02 +02:00
parent c2dc3109ae
commit f9208c0b3d
4 changed files with 51 additions and 10 deletions

View File

@ -217,18 +217,18 @@ static void status_arg(void)
puts(_("calcurse is not running\n")); puts(_("calcurse is not running\n"));
} }
/* Print TODO list and exit. */ /* Print TODO list and return the number of printed items. */
static void todo_arg(const char *format, int *limit, static int todo_arg(const char *format, int *limit, struct item_filter *filter)
struct item_filter *filter)
{ {
const char *titlestr = const char *titlestr =
filter->completed ? _("completed tasks:\n") : _("to do:\n"); filter->completed ? _("completed tasks:\n") : _("to do:\n");
int title = 1; int title = 1;
int n = 0;
llist_item_t *i; llist_item_t *i;
LLIST_FOREACH(&todolist, i) { LLIST_FOREACH(&todolist, i) {
if (*limit == 0) if (*limit == 0)
return; break;
struct todo *todo = LLIST_TS_GET_DATA(i); struct todo *todo = LLIST_TS_GET_DATA(i);
if (title) { if (title) {
@ -236,8 +236,11 @@ static void todo_arg(const char *format, int *limit,
title = 0; title = 0;
} }
print_todo(format, todo); print_todo(format, todo);
n++;
(*limit)--; (*limit)--;
} }
return n;
} }
/* Print the next appointment within the upcoming 24 hours. */ /* Print the next appointment within the upcoming 24 hours. */
@ -286,11 +289,11 @@ static void arg_print_date(long date)
* If no end date is given (-1), a range of 1 day is considered. * If no end date is given (-1), a range of 1 day is considered.
*/ */
static void static void
date_arg_from_to(long from, long to, const char *fmt_apt, const char *fmt_rapt, date_arg_from_to(long from, long to, int add_line, const char *fmt_apt,
const char *fmt_ev, const char *fmt_rev, int *limit) const char *fmt_rapt, const char *fmt_ev, const char *fmt_rev,
int *limit)
{ {
long date; long date;
int add_line = 0;
for (date = from; date < to; date += DAYINSEC) { for (date = from; date < to; date += DAYINSEC) {
day_store_items(date, 0); day_store_items(date, 0);
@ -659,9 +662,9 @@ int parse_args(int argc, char **argv)
config_load(); /* To get output date format. */ config_load(); /* To get output date format. */
io_load_app(&filter); io_load_app(&filter);
io_load_todo(&filter); io_load_todo(&filter);
date_arg_from_to(from, to, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, int add_line = todo_arg(fmt_todo, &limit, &filter);
&limit); date_arg_from_to(from, to, add_line, fmt_apt, fmt_rapt, fmt_ev,
todo_arg(fmt_todo, &limit, &filter); fmt_rev, &limit);
} else if (next) { } else if (next) {
io_check_file(path_apts); io_check_file(path_apts);
io_load_app(&filter); io_load_app(&filter);

View File

@ -41,6 +41,7 @@ TESTS = \
event-004.sh \ event-004.sh \
event-005.sh \ event-005.sh \
event-006.sh \ event-006.sh \
filter-001.sh \
ical-001.sh \ ical-001.sh \
ical-002.sh \ ical-002.sh \
ical-003.sh \ ical-003.sh \
@ -98,6 +99,7 @@ EXTRA_DIST = \
data/apts-event-004 \ data/apts-event-004 \
data/apts-event-005 \ data/apts-event-005 \
data/apts-event-006 \ data/apts-event-006 \
data/apts-filter-001 \
data/apts-recur \ data/apts-recur \
data/conf \ data/conf \
data/ical-001.ical \ data/ical-001.ical \

View File

@ -0,0 +1,8 @@
02/22/2013 [1] Event 1
02/23/2013 [1] Event 2
02/24/2013 [1] Event 3
02/25/2013 [1] Event 4
02/22/2013 @ 10:00 -> 02/22/2013 @ 12:00 |Appointment 1
02/23/2013 @ 10:00 -> 02/23/2013 @ 12:00 |Appointment 2
02/24/2013 @ 10:00 -> 02/24/2013 @ 12:00 |Appointment 3
02/25/2013 @ 10:00 -> 02/25/2013 @ 12:00 |Appointment 4

28
test/filter-001.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
. "${TEST_INIT:-./test-init.sh}"
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-filter-001" \
-t9 -s02/23/2013 -r2
elif [ "$1" = 'expected' ]; then
cat <<EOD
to do:
9. Gloriously slams
9. Beefburger's
9. Seasons
02/23/13:
* Event 2
- 10:00 -> 12:00
Appointment 2
02/24/13:
* Event 3
- 10:00 -> 12:00
Appointment 3
EOD
else
./run-test "$0"
fi