diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-20 10:09:41 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-20 10:09:41 +0200 |
| commit | 5097941fa96ce0c309e5f1af034993781a70fc66 (patch) | |
| tree | ff46ced172d475046994a6c23b0cae20b693e12f /clients | |
| parent | fed4952b5e9e6bc6f9f6ca4a30570b0b898ee953 (diff) | |
| download | bokf-5097941fa96ce0c309e5f1af034993781a70fc66.tar.gz bokf-5097941fa96ce0c309e5f1af034993781a70fc66.zip | |
tui: align list rows beyond nine itemsv0.1.47
Diffstat (limited to 'clients')
| -rw-r--r-- | clients/tui.c | 15 | ||||
| -rw-r--r-- | clients/tui.h | 1 |
2 files changed, 11 insertions, 5 deletions
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; diff --git a/clients/tui.h b/clients/tui.h index 7250c0b..fcab5b7 100644 --- a/clients/tui.h +++ b/clients/tui.h @@ -61,6 +61,7 @@ void tui_keys_setup(void); /* --- text measure and formatting --- */ int tui_disp_width(const char *s); int tui_disp_width_n(const char *s, size_t n); +int tui_num_width(int n); void tui_pad_field(char *buf, size_t cap, int width); void tui_pad_label(char *buf, size_t n, const char *text, int width); void tui_pad_hdr(char *buf, size_t n, int width, const char *text); |
