foxygit / Hush Log in
commits tags

/src/config.h · 1.46 KB

raw
#ifndef HUSH_CONFIG_H
#define HUSH_CONFIG_H

#include "clay.h"
#include "fonts.h"
#include "keymap.h"
#include <stdbool.h>

typedef struct {
    Clay_Color textColor;
    Clay_Color bgColor;
    char *fontPaths[FONT_COUNT]; /* malloc'd override path per slot, or NULL = bundled default */
    char *language; /* malloc'd language code (e.g. "sv"), passed to lang_load(); never NULL */
    float zoom; /* starting zoom level (1.0 = 100%); Ctrl+/Ctrl- still adjust it during the session */
    KeyBinding keymap[ACTION_COUNT]; /* defaults from keymap_set_defaults(), overridable via "key.*" lines */
} Config;

/* Fills `out` with the built-in defaults, then overlays whatever is set in the user's config
   file (XDG_CONFIG_HOME/hush/config, or ~/.config/hush/config). If no config file exists yet,
   creates one there with every key present but commented out, showing the defaults, so it's
   self-documenting on first run. Always returns true -- filesystem failures (can't read, can't
   create the default file, no $HOME) are non-fatal and just leave `out` at its defaults. */
bool config_load(Config *out);
void config_free(Config *cfg);

/* Exposed for headless unit testing of the line parser without touching a real file. Returns
   true if the line set a recognized key on `cfg`; false for comments/blank/unrecognized/
   malformed lines -- never fatal, so a typo in a hand-edited file can't stop hush from starting. */
bool config_parse_line(const char *line, int len, Config *cfg);

#endif