aboutsummaryrefslogtreecommitdiff
path: root/clients/bokftui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-18 21:21:26 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-18 21:21:26 +0200
commit64c0d5d79b31dafcbdb68ff938a92bd6f136d4a7 (patch)
tree6d8d06b1277a5ac284006e71ea2e5d4dd55955fc /clients/bokftui.c
parent49343ab72fa388aeba155c0fa605efdbfd8a345a (diff)
downloadbokf-64c0d5d79b31dafcbdb68ff938a92bd6f136d4a7.tar.gz
bokf-64c0d5d79b31dafcbdb68ff938a92bd6f136d4a7.zip
bokftui: align report columns when labels contain å/ä/ö
printf widths count bytes, so Swedish labels shifted every following column by one per multi-byte character: Huvudbok's Ingående/Omslutning/ Utgående saldo lines, moms ruta 48/49, and the Resultatrapport, Saldobalans and Verifikationslista headers no longer lined up with their rows. pad_min() pads to display columns without truncating long moms labels and pad_hdr() right-aligns headers; the Ingående balans/saldo amounts now sit in the far-right Saldo column like the Kapitas export.
Diffstat (limited to 'clients/bokftui.c')
-rw-r--r--clients/bokftui.c79
1 files changed, 58 insertions, 21 deletions
diff --git a/clients/bokftui.c b/clients/bokftui.c
index b2d8e42..eedf5fc 100644
--- a/clients/bokftui.c
+++ b/clients/bokftui.c
@@ -2662,6 +2662,26 @@ static int acct_in(const char *number, int lo, int hi)
return n >= lo && n <= hi;
}
+/* Pad to `width` display columns without truncating (labels may be longer). */
+static void pad_min(char *buf, size_t n, int width)
+{
+ int w = disp_width(buf);
+ size_t len = strlen(buf);
+ while (w < width && len + 1 < n) {
+ buf[len++] = ' ';
+ buf[len] = '\0';
+ w++;
+ }
+}
+
+/* Right-align `text` in `width` display columns (headers with å/ä/ö). */
+static void pad_hdr(char *buf, size_t n, int width, const char *text)
+{
+ int w = disp_width(text);
+ int pad = width > w ? width - w : 0;
+ snprintf(buf, n, "%*s%s", pad, "", text);
+}
+
static void pad_label(char *buf, size_t n, const char *text, int width)
{
snprintf(buf, n, "%s", text);
@@ -2941,9 +2961,12 @@ static void fmt_resultat(struct buf *t, const struct app *a, yyjson_val *res,
buf_line(t, "\n");
buf_line(t, "%s\n", gr->section);
} else {
- buf_line(t, " %5s %-48s %15s %15s %15s\n", "",
- gr->section, "Period", "Ackumulerat",
- "Föreg. per.");
+ char lbl[80], h1[32], h2[32], h3[32];
+ pad_label(lbl, sizeof lbl, gr->section, 48);
+ pad_hdr(h1, sizeof h1, 15, "Period");
+ pad_hdr(h2, sizeof h2, 15, "Ackumulerat");
+ pad_hdr(h3, sizeof h3, 15, "Föreg. per.");
+ buf_line(t, " %5s %s %s %s %s\n", "", lbl, h1, h2, h3);
buf_rule(t, IS_RULE_W);
buf_line(t, "\n");
buf_line(t, "%s\n", gr->title);
@@ -3056,8 +3079,13 @@ static void fmt_saldobalans(struct buf *t, const struct app *a,
yyjson_val *res)
{
fmt_head(t, a, "Saldobalans", res);
- buf_line(t, " %5s %-48s %14s %14s %14s %14s\n", "Konto", "Benämning",
- "Ingående", "Debet", "Kredit", "Utgående");
+ char nmh[64], h1[32], h2[32], h3[32], h4[32];
+ pad_label(nmh, sizeof nmh, "Benämning", 48);
+ pad_hdr(h1, sizeof h1, 14, "Ingående");
+ pad_hdr(h2, sizeof h2, 14, "Debet");
+ pad_hdr(h3, sizeof h3, 14, "Kredit");
+ pad_hdr(h4, sizeof h4, 14, "Utgående");
+ buf_line(t, " %5s %s %s %s %s %s\n", "Konto", nmh, h1, h2, h3, h4);
buf_rule(t, BS_RULE_W);
yyjson_val *arr = yyjson_obj_get(res, "accounts");
size_t n = yyjson_arr_size(arr);
@@ -3172,10 +3200,12 @@ static void fmt_moms(struct buf *t, const struct app *a, yyjson_val *res)
break;
}
}
- char amt[48] = "";
+ char amt[48] = "", lbl[192];
if (ore)
kr_whole(ore, amt, sizeof amt);
- buf_line(t, "%s. %-66s %14s\n", vr->box, vr->label, amt);
+ snprintf(lbl, sizeof lbl, "%s", vr->label);
+ pad_min(lbl, sizeof lbl, 66);
+ buf_line(t, "%s. %s %14s\n", vr->box, lbl, amt);
}
int64_t ore49 = 0;
for (size_t j = 0; j < n; j++) {
@@ -3187,10 +3217,12 @@ static void fmt_moms(struct buf *t, const struct app *a, yyjson_val *res)
}
buf_line(t, "\nG. %s\n", vat_section_title("G."));
buf_rule(t, 87);
- char amt49[48];
+ char amt49[48], lbl49[192];
kr_whole(ore49, amt49, sizeof amt49);
- buf_line(t, "49. %-66s %14s\n",
- "Moms att betala (+) eller att få tillbaka (-)", amt49);
+ snprintf(lbl49, sizeof lbl49, "%s",
+ "Moms att betala (+) eller att få tillbaka (-)");
+ pad_min(lbl49, sizeof lbl49, 66);
+ buf_line(t, "49. %s %14s\n", lbl49, amt49);
}
static int64_t prev_fy_id(struct app *a)
@@ -3244,8 +3276,11 @@ static void fmt_huvudbok(struct buf *t, const struct app *a, yyjson_val *res)
buf_line(t, "\n%s %s\n\n", vstr(ao, "account"), vstr(ao, "name"));
char a1[48];
amt_col(a1, sizeof a1, 16, ib);
- buf_line(t, " %-59s %16s\n", "Ingående balans:", a1);
- buf_line(t, " %-59s %16s\n", "Ingående saldo:", a1);
+ char lbl[96];
+ pad_label(lbl, sizeof lbl, "Ingående balans:", 59);
+ buf_line(t, " %s %14s %14s %16s\n", lbl, "", "", a1);
+ pad_label(lbl, sizeof lbl, "Ingående saldo:", 59);
+ buf_line(t, " %s %14s %14s %16s\n", lbl, "", "", a1);
buf_line(t, "\n");
yyjson_val *rows = yyjson_obj_get(ao, "rows");
size_t nr = yyjson_arr_size(rows);
@@ -3270,11 +3305,11 @@ static void fmt_huvudbok(struct buf *t, const struct app *a, yyjson_val *res)
amt_col(s1, sizeof s1, 14, d);
amt_col(s2, sizeof s2, 14, c);
amt_col(s3, sizeof s3, 16, d - c);
- buf_line(t, " %-59s %14s %14s %16s\n", "Omslutning:", s1, s2,
- s3);
+ pad_label(lbl, sizeof lbl, "Omslutning:", 59);
+ buf_line(t, " %s %14s %14s %16s\n", lbl, s1, s2, s3);
amt_col(s3, sizeof s3, 16, vint(ao, "ub_ore"));
- buf_line(t, " %-59s %14s %14s %16s\n", "Utgående saldo:", s1,
- s2, s3);
+ pad_label(lbl, sizeof lbl, "Utgående saldo:", 59);
+ buf_line(t, " %s %14s %14s %16s\n", lbl, s1, s2, s3);
}
}
@@ -3288,8 +3323,10 @@ static void fmt_verifikationslista(struct buf *t, const struct app *a,
if (lv)
buf_line(t, "Senaste ver.: %s%lld\n\n", vstr(lv, "series"),
(long long)vint(lv, "number"));
- buf_line(t, "%-8s %-10s %-48s %14s %14s\n", "Ver.", "Datum/Konto",
- "Benämning", "Debet", "Kredit");
+ char nmh[64];
+ pad_label(nmh, sizeof nmh, "Benämning", 48);
+ buf_line(t, "%-8s %-11s %s %14s %14s\n", "Ver.", "Datum/Konto", nmh,
+ "Debet", "Kredit");
buf_rule(t, 98);
yyjson_val *vs = yyjson_obj_get(res, "vouchers");
size_t n = yyjson_arr_size(vs);
@@ -3298,7 +3335,7 @@ static void fmt_verifikationslista(struct buf *t, const struct app *a,
char ver[32];
snprintf(ver, sizeof ver, "%s%lld", vstr(vo, "series"),
(long long)vint(vo, "number"));
- buf_line(t, "%-8s %-10s %s\n", ver, vstr(vo, "date"),
+ buf_line(t, "%-8s %-11s %s\n", ver, vstr(vo, "date"),
vstr(vo, "description"));
yyjson_val *rows = yyjson_obj_get(vo, "rows");
size_t nr = yyjson_arr_size(rows);
@@ -3310,7 +3347,7 @@ static void fmt_verifikationslista(struct buf *t, const struct app *a,
amt_col(cc, sizeof cc, 14, vint(ro, "credit_ore"));
snprintf(deb, sizeof deb, "%s", vint(ro, "debit_ore") ? dd : "");
snprintf(kre, sizeof kre, "%s", vint(ro, "credit_ore") ? cc : "");
- buf_line(t, " %-10s %s %14s %14s\n", vstr(ro, "account"),
+ buf_line(t, " %-10s %s %14s %14s\n", vstr(ro, "account"),
nm, deb, kre);
}
}
@@ -3318,7 +3355,7 @@ static void fmt_verifikationslista(struct buf *t, const struct app *a,
char s1[48], s2[48];
amt_col(s1, sizeof s1, 14, vint(tot, "debit_ore"));
amt_col(s2, sizeof s2, 14, vint(tot, "credit_ore"));
- buf_line(t, "\n%-68s %14s %14s\n", "Omslutning:", s1, s2);
+ buf_line(t, "\n%-69s %14s %14s\n", "Omslutning:", s1, s2);
}
static void reports_screen(struct app *a)