diff options
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 35 |
1 files changed, 11 insertions, 24 deletions
@@ -722,31 +722,18 @@ log_message_attributed (void *user_data, const char *quote, const char *fmt, static void init_colors (struct app_context *ctx) { + bool have_ti = init_terminal (); + // Use escape sequences from terminfo if possible, and SGR as a fallback - if (init_terminal ()) - { - const char *attrs[][2] = - { - { ATTR_PROMPT, enter_bold_mode }, - { ATTR_RESET, exit_attribute_mode }, - { ATTR_WARNING, g_terminal.color_set[3] }, - { ATTR_ERROR, g_terminal.color_set[1] }, - }; - for (size_t i = 0; i < N_ELEMENTS (attrs); i++) - str_map_set (&ctx->config, attrs[i][0], xstrdup (attrs[i][1])); - } - else - { - const char *attrs[][2] = - { - { ATTR_PROMPT, "\x1b[1m" }, - { ATTR_RESET, "\x1b[0m" }, - { ATTR_WARNING, "\x1b[33m" }, - { ATTR_ERROR, "\x1b[31m" }, - }; - for (size_t i = 0; i < N_ELEMENTS (attrs); i++) - str_map_set (&ctx->config, attrs[i][0], xstrdup (attrs[i][1])); - } +#define INIT_ATTR(id, ti, vt100) \ + str_map_set (&ctx->config, (id), xstrdup (have_ti ? (ti) : (vt100))); + + INIT_ATTR (ATTR_PROMPT, enter_bold_mode, "\x1b[1m"); + INIT_ATTR (ATTR_RESET, exit_attribute_mode, "\x1b[0m"); + INIT_ATTR (ATTR_WARNING, g_terminal.color_set[3], "\x1b[33m"); + INIT_ATTR (ATTR_ERROR, g_terminal.color_set[1], "\x1b[31m"); + +#undef INIT_ATTR switch (ctx->color_mode) { |