summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-21 20:52:41 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-21 20:52:41 +0200
commit69582c9e1444d3448ef43d19f39c0ed498d723a6 (patch)
tree2cd98b2aba334c652ea22fa5ee09f95b0d9bc926
parentc69c8048b456d1e51617c26bd9ddb2e9e10c658e (diff)
downloadxK-69582c9e1444d3448ef43d19f39c0ed498d723a6.tar.gz
xK-69582c9e1444d3448ef43d19f39c0ed498d723a6.tar.xz
xK-69582c9e1444d3448ef43d19f39c0ed498d723a6.zip
degesch: shorten/dedup init_colors()
-rw-r--r--degesch.c35
1 files changed, 11 insertions, 24 deletions
diff --git a/degesch.c b/degesch.c
index b00e7b6..ac44a71 100644
--- a/degesch.c
+++ b/degesch.c
@@ -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)
{