diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-10-20 19:04:47 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-10-20 19:04:47 +0000 |
| commit | 2c101a21ee6df096dadd60a77b4cb190f8503490 (patch) | |
| tree | 44cd2bbd1e92c7a075f22e9e8f991ae064e49774 /config.c | |
| parent | osc: change info logging to debug logging when changing the cursor color (diff) | |
config: add font-bold, font-italic and font-bold-italic options
These options lets the user configure custom fonts and styles, to use
with the bold and italic cell attributes.
By default, they are unset, meaning we use the bold/italic variants of
the regular font.
Closes #169.
Diffstat (limited to 'config.c')
| -rw-r--r-- | config.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -547,14 +547,28 @@ parse_section_main(const char *key, const char *value, struct config *conf, } } - else if (strcmp(key, "font") == 0) { + else if (strcmp(key, "font") == 0 || + strcmp(key, "font-bold") == 0 || + strcmp(key, "font-italic") == 0 || + strcmp(key, "font-bold-italic") == 0) + + { + size_t idx = + strcmp(key, "font") == 0 ? 0 : + strcmp(key, "font-bold") == 0 ? 1 : + strcmp(key, "font-italic") == 0 ? 2 : 3; + + tll_foreach(conf->fonts[idx], it) + config_font_destroy(&it->item); + tll_free(conf->fonts[idx]); + char *copy = xstrdup(value); for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ",")) { /* Trim spaces, strictly speaking not necessary, but looks nice :) */ while (*font != '\0' && isspace(*font)) font++; if (*font != '\0') - tll_push_back(conf->fonts, config_font_parse(font)); + tll_push_back(conf->fonts[idx], config_font_parse(font)); } free(copy); } @@ -1904,7 +1918,7 @@ config_load(struct config *conf, const char *conf_path, .pad_y = 2, .bell_is_urgent = false, .startup_mode = STARTUP_WINDOWED, - .fonts = tll_init(), + .fonts = {tll_init(), tll_init(), tll_init(), tll_init()}, .scrollback = { .lines = 1000, .indicator = { @@ -2028,8 +2042,8 @@ config_load(struct config *conf, const char *conf_path, conf->colors.selection_bg >> 24 == 0; out: - if (ret && tll_length(conf->fonts) == 0) - tll_push_back(conf->fonts, config_font_parse("monospace")); + if (ret && tll_length(conf->fonts[0]) == 0) + tll_push_back(conf->fonts[0], config_font_parse("monospace")); free(conf_file.path); if (conf_file.fd >= 0) @@ -2047,9 +2061,11 @@ config_free(struct config conf) free(conf.app_id); free(conf.word_delimiters); free(conf.scrollback.indicator.text); - tll_foreach(conf.fonts, it) - config_font_destroy(&it->item); - tll_free(conf.fonts); + for (size_t i = 0; i < ALEN(conf.fonts); i++) { + tll_foreach(conf.fonts[i], it) + config_font_destroy(&it->item); + tll_free(conf.fonts[i]); + } free(conf.server_socket_path); tll_foreach(conf.bindings.key, it) { |
