summaryrefslogtreecommitdiff
path: root/clients/bokftui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-23 09:34:16 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-23 09:34:16 +0200
commit79b27457125dc2e259783359085021eea1d26e3a (patch)
treee5b733b642437d34d46ee34514b093daee52fcef /clients/bokftui.c
parent6159042d0cb3870e6a7c6f8d9a97e175d59e6f80 (diff)
downloadbokf-79b27457125dc2e259783359085021eea1d26e3a.tar.gz
bokf-79b27457125dc2e259783359085021eea1d26e3a.zip
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 <noreply@anthropic.com>
Diffstat (limited to 'clients/bokftui.c')
-rw-r--r--clients/bokftui.c19
1 files changed, 12 insertions, 7 deletions
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)