From 69582c9e1444d3448ef43d19f39c0ed498d723a6 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 21 Apr 2015 20:52:41 +0200
Subject: degesch: shorten/dedup init_colors()
---
degesch.c | 35 +++++++++++------------------------
1 file 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)
{
--
cgit v1.2.3-70-g09d2