#ifndef BOKF_UI_H #define BOKF_UI_H #include #include #include "client.h" #include "tui.h" #include "util.h" #include "yyjson.h" /* Shared UI state and helpers for the bokftui screens (screens_.c). The scene registry and main() live in bokftui.c. */ /* universal "new/add" hotkey: ^N (0x0e), the de-facto Linux convention */ #define KEY_CTRL_N 0x0e /* ^X clears the focused row in row editors */ #define KEY_CTRL_X 0x18 /* ^Enter saves/posts the form; sent via xterm modifyOtherKeys */ #define KEY_CTRL_ENTER (KEY_MAX + 1) /* Pager markup: headings, dimmed derived lines and full-width rules. */ #define MK_HEAD "\001" #define MK_DIM "\002" #define MK_RULE "\003" #define MK_STICKY "\004" /* Menu item prefix for a non-selectable section header. */ #define MK_SECTION MK_HEAD struct app { struct client_conn conn; char socket[256]; char session[128]; char username[64]; char password[128]; /* typed or from BOKFD_PASSWORD, kept for ^R */ int64_t org; char org_name[128]; char role[32]; int64_t fy; int64_t voucher_sel; /* last selected voucher id in the list view */ int64_t invoice_sel; /* last selected invoice id in the list view */ int64_t customer_sel; /* last selected customer id in the list view */ char default_series[16]; char attachment_dir[256]; long max_attachment_bytes; char fy_label[64]; char fy_start[16]; char fy_end[16]; }; /* ^C quits the application; Esc is navigation only */ extern int g_quit; /* ^R re-execs the binary, keeping session, org, year and screen */ extern int g_reload; extern char g_scene[32]; extern char g_reload_scene[32]; extern char g_server_version[32]; /* json helpers */ yyjson_val *jget(yyjson_val *root, const char *path); yyjson_doc *parse(const char *resp); char *jstr_dup(const char *resp, const char *path); int64_t jint_val(const char *resp, const char *path, int64_t def); size_t jarr_size(const char *resp, const char *path); int jbool_val(const char *resp, const char *path, int def); /* shared UI primitives */ int ui_getch(void); void request_quit(void); void tui_log(const char *fmt, ...) __attribute__((format(printf, 1, 2))); void show_error(const char *title, const char *resp); void kr_whole(int64_t ore, char *buf, size_t n); int parse_x_double(const char *s, double *out); void replace_x_into(const char *src, double x, char *dst, size_t cap); void app_refresh_context(struct app *a); char *rpc_dry(struct app *a, const char *cmd, const char *args); char *read_file_b64(const char *path); char *file_browser(struct app *a, const char *start_dir); void attachment_download(struct app *a, int64_t att_id); int64_t pick_voucher(struct app *a); /* generated-document helpers (reports, bokslut) */ void buf_line(struct buf *b, const char *fmt, ...) __attribute__((format(printf, 2, 3))); void buf_rule(struct buf *b, int width); const char *vstr(yyjson_val *o, const char *k); int64_t vint(yyjson_val *o, const char *k); int acct_in(const char *number, int lo, int hi); extern const char *const BS_KEYS[3]; struct is_group { const char *section; const char *title; int lo, hi; int rev; }; #define IS_GROUPS_N 7 extern const struct is_group IS_GROUPS[IS_GROUPS_N]; /* defined in bokftui.c, used by screens */ void open_scene(struct app *a, const char *name); void config_mkdirs(const char *path); /* Optional prefill for the new-voucher form (bank reconciliation). */ struct voucher_prefill { const char *date; /* YYYY-MM-DD, may be NULL */ const char *description; /* voucher text, may be NULL */ const char *bank_account; /* account number for the prefilled row */ int64_t amount_ore; /* > 0 debits the bank account, < 0 credits it */ }; /* screen entry points (scene registry) */ void dashboard(struct app *a); void update_status(struct app *a); int64_t vouchers_new(struct app *a); int64_t vouchers_new_prefill(struct app *a, const struct voucher_prefill *p); void vouchers_screen(struct app *a); void acct_cache_free(void); const char *acct_name(struct app *a, const char *number); int acct_exists(struct app *a, const char *number); void accounts_report(struct app *a); void reports_screen(struct app *a); void ink2_screen(struct app *a); void rules_screen(struct app *a); void inbox_screen(struct app *a); void bank_screen(struct app *a); void audit_screen(struct app *a); void templates_screen(struct app *a); void ib_screen(struct app *a); void settings_screen(struct app *a); void company_screen(struct app *a); void invoices_screen(struct app *a); void customers_screen(struct app *a); void bokslut_screen(struct app *a); #endif