diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-22 12:43:52 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-22 12:43:52 +0200 |
| commit | 07f5b140922d13519ad7a0d1dad67a9b403be9f1 (patch) | |
| tree | b6dde2ed6adb90c6423a5e585b693b908637e5ee /clients/drafts.h | |
| parent | 760cb25bd220718e37d8b95016f30cdf8ef6acdc (diff) | |
| download | bokf-07f5b140922d13519ad7a0d1dad67a9b403be9f1.tar.gz bokf-07f5b140922d13519ad7a0d1dad67a9b403be9f1.zip | |
tui: kundutkast, <UTKAST>, explicit Spara och F2-åtgärder
Diffstat (limited to 'clients/drafts.h')
| -rw-r--r-- | clients/drafts.h | 49 |
1 files changed, 49 insertions, 0 deletions
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 <stddef.h> +#include <stdint.h> + +/* 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-<time>-<seq>", unique within the process. Caller frees. */ +char *drafts_new_id(void); + +#endif |
