From 5097941fa96ce0c309e5f1af034993781a70fc66 Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Sun, 20 Sep 2026 10:09:41 +0200 Subject: tui: align list rows beyond nine items --- clients/tui.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'clients/tui.c') diff --git a/clients/tui.c b/clients/tui.c index c52538c..06740d3 100644 --- a/clients/tui.c +++ b/clients/tui.c @@ -191,6 +191,14 @@ int tui_disp_width_n(const char *s, size_t n) return w; } +int tui_num_width(int n) +{ + int w = 1; + for (int tmp = n; tmp >= 10; tmp /= 10) + w++; + return w; +} + void tui_le_init(struct tui_ledit *e, char *buf, size_t cap) { e->buf = buf; @@ -1020,8 +1028,7 @@ int tui_select_list_hook(const char *title, char **items, int n, int start, if (n > 0 && v.sel >= n) v.sel = n - 1; v.view = LINES - 4; - for (int tmp = n; tmp >= 10; tmp /= 10) - v.numw++; + v.numw = tui_num_width(n); snprintf(v.gotolabel, sizeof v.gotolabel, "Gå till rad: "); for (;;) { if (cursor) @@ -1078,9 +1085,7 @@ int tui_menu(const char *title, const char *const *items, int n, v.sel = (cursor && *cursor >= 0 && *cursor < n) ? *cursor : 0; if (!flags[v.sel]) v.sel = nav_snap(&v, v.sel, 1); - v.numw = 1; - for (int tmp = nsel; tmp >= 10; tmp /= 10) - v.numw++; + v.numw = tui_num_width(nsel); if (v.numw < 2) v.numw = 2; v.view = (LINES - 4) / 2; -- cgit v1.3