From 07f5b140922d13519ad7a0d1dad67a9b403be9f1 Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Tue, 22 Sep 2026 12:43:52 +0200 Subject: tui: kundutkast, , explicit Spara och F2-åtgärder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clients/drafts.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 clients/drafts.h (limited to 'clients/drafts.h') diff --git a/clients/drafts.h b/clients/drafts.h new file mode 100644 index 0000000..2cc67db --- /dev/null +++ b/clients/drafts.h @@ -0,0 +1,49 @@ +#ifndef BOKF_DRAFTS_H +#define BOKF_DRAFTS_H + +#include +#include + +/* Client-local edit drafts: every non-committed edit is mirrored to + $XDG_CACHE_HOME/bokf/drafts.json (mode 0600, atomic replace) so a reload, + a crash or Ctrl+C never loses work. A record is keyed by + (org, entity, id); a new entity uses a temporary id from + drafts_new_id(). See docs/TUI-GUIDELINES.md "Interaction model". */ + +struct draft { + int64_t org; + char *entity; + char *id; + char *fields; /* JSON object text */ +}; + +struct drafts { + struct draft *v; + size_t n, cap; + char path[600]; +}; + +void drafts_init(struct drafts *d); +/* Explicit path, for tests. */ +void drafts_init_path(struct drafts *d, const char *path); +void drafts_free(struct drafts *d); + +/* The draft's fields JSON, or NULL; the store owns the string. */ +const char *drafts_get(const struct drafts *d, int64_t org, + const char *entity, const char *id); +int drafts_have(const struct drafts *d, int64_t org, const char *entity, + const char *id); +/* Inserts or replaces the draft and persists the file. */ +void drafts_put(struct drafts *d, int64_t org, const char *entity, + const char *id, const char *fields); +void drafts_del(struct drafts *d, int64_t org, const char *entity, + const char *id); +size_t drafts_count(const struct drafts *d, int64_t org, const char *entity); +void drafts_foreach(const struct drafts *d, int64_t org, const char *entity, + void (*cb)(void *ud, const char *id, const char *fields), + void *ud); + +/* "ny-