From 79b27457125dc2e259783359085021eea1d26e3a Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Wed, 23 Sep 2026 09:34:16 +0200 Subject: tui: "Byt bolag" in the main menu Reopens the org picker (cursor on the current org) and switches the running session: the org's name, role, current fiscal year and series are reloaded and the remembered list selections cleared. The context reload now clears the previous org's values first. Co-Authored-By: Claude Opus 5.5 --- clients/bokftui.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'clients/bokftui.c') diff --git a/clients/bokftui.c b/clients/bokftui.c index 867e63e..19a63cf 100644 --- a/clients/bokftui.c +++ b/clients/bokftui.c @@ -286,7 +286,9 @@ static int login_screen(struct app *a) } } -static int select_org(struct app *a) +/* Org picker; the cursor starts on the current org. 0 when one was + chosen (a->org set), -1 on Esc or error. */ +int select_org(struct app *a) { char *resp = client_rpc(&a->conn, "session.list_orgs", a->session, 0, "{}"); if (!resp || !client_ok(resp)) { @@ -319,17 +321,20 @@ static int select_org(struct app *a) free(name); free(role); } - int sel = tui_select_list("Välj organisation att representera", items, (int)n, - 0, 0, NULL, 0, NULL, 0); + int start = 0; + for (size_t i = 0; i < n; i++) + if (ids[i] == a->org) + start = (int)i; + int sel = tui_select_list("Välj organisation att representera", items, + (int)n, start, 0, NULL, 0, NULL, 0); for (size_t i = 0; i < n; i++) free(items[i]); free(items); free(resp); - if (sel < 0) - return -1; - a->org = ids[sel]; + if (sel >= 0) + a->org = ids[sel]; free(ids); - return 0; + return sel >= 0 ? 0 : -1; } static void usage(FILE *f) -- cgit v1.3