From 53071bb69f5d21b35b8a61c2b1dd18832ce781d4 Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Wed, 23 Sep 2026 09:13:17 +0200 Subject: tui: aligned voucher detail, up/down between vouchers, list sorting The detail pads every column by display width, blanks zero amounts and shows row texts and a Summa line. Up/Down step to the previous/next voucher in the list order; 's' cycles the list sort (number or date, ascending or descending, saved in tui.conf). The list fetches all pages of voucher.list instead of stopping at 200. Co-Authored-By: Claude Opus 5.5 --- clients/vlist.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 clients/vlist.h (limited to 'clients/vlist.h') diff --git a/clients/vlist.h b/clients/vlist.h new file mode 100644 index 0000000..8324ade --- /dev/null +++ b/clients/vlist.h @@ -0,0 +1,46 @@ +#ifndef BOKF_VLIST_H +#define BOKF_VLIST_H + +#include +#include + +/* Voucher list ordering and stepping for the Verifikat view. Pure, so it is + unit-tested in tests/test_tui.c. */ + +struct vlist_item { + int64_t id; + char series[16]; + int64_t number; + char date[16]; + char *desc; /* owned by the caller */ + int attachments; +}; + +enum { + VSORT_NUMBER = 0, /* series, then number, ascending */ + VSORT_NUMBER_DESC, + VSORT_DATE, /* date, then series and number, ascending */ + VSORT_DATE_DESC, + VSORT_COUNT, +}; + +/* Sorts in place; ties fall back to the id so the order is stable. An + out-of-range mode sorts by number. */ +void vlist_sort(struct vlist_item *v, size_t n, int mode); + +/* Swedish label for the list title, e.g. "datum, fallande". */ +const char *vlist_sort_label(int mode); + +/* Config value ("number", "number-desc", "date", "date-desc") and back; + an unknown name gives VSORT_NUMBER. */ +const char *vlist_sort_name(int mode); +int vlist_sort_parse(const char *name); + +/* Index of the item with this id, or -1. */ +int vlist_index(const struct vlist_item *v, size_t n, int64_t id); + +/* Index dir steps from idx, or -1 past either end or when idx is not in + the list. */ +int vlist_step(size_t n, int idx, int dir); + +#endif -- cgit v1.3