]> granicus.if.org Git - neomutt/commitdiff
encapsulate defs
authorRichard Russon <rich@flatcap.org>
Fri, 4 Oct 2019 01:10:17 +0000 (02:10 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 8 Oct 2019 22:45:06 +0000 (23:45 +0100)
color.c

diff --git a/color.c b/color.c
index 763d5fc000c4a5ddf49341fdd7443425dc3bf8a9..ce4b1df4857e05302f10296832c86f55817d60e5 100644 (file)
--- a/color.c
+++ b/color.c
@@ -152,6 +152,43 @@ static const struct Mapping ComposeFields[] = {
 };
 // clang-format off
 
+/**
+ * defs_free - Free the simple colour definitions
+ * @param c Colours
+ */
+static void defs_free(struct Colors *c)
+{
+  FREE(&c->defs);
+}
+
+/**
+ * defs_init - Initialise the simple colour definitions
+ * @param c Colours
+ */
+static void defs_init(struct Colors *c)
+{
+  c->defs = mutt_mem_malloc(MT_COLOR_MAX * sizeof(int));
+  memset(c->defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
+
+  // Set some defaults
+  c->defs[MT_COLOR_STATUS] = A_REVERSE;
+  c->defs[MT_COLOR_INDICATOR] = A_REVERSE;
+  c->defs[MT_COLOR_SEARCH] = A_REVERSE;
+  c->defs[MT_COLOR_MARKERS] = A_REVERSE;
+#ifdef USE_SIDEBAR
+  c->defs[MT_COLOR_SIDEBAR_HIGHLIGHT] = A_UNDERLINE;
+#endif
+}
+
+/**
+ * defs_clear - Reset the simple colour definitions
+ * @param c Colours
+ */
+static void defs_clear(struct Colors *c)
+{
+  memset(c->defs, A_NORMAL, MT_COLOR_MAX * sizeof(int));
+}
+
 /**
  * color_line_new - Create a new ColorLine
  * @retval ptr Newly allocated ColorLine
@@ -203,30 +240,27 @@ static void color_line_list_clear(struct ColorLineList *list)
   }
 }
 
+/**
+ * colors_clear - Reset all the colours
+ * @param c Colours
+ */
+static void colors_clear(struct Colors *c)
+{
+  defs_clear(c);
+}
+
 /**
  * mutt_color_init - Set up the default colours
  */
 void mutt_color_init(void)
 {
   Colors = mutt_mem_calloc(1, sizeof(*Colors));
-  Colors->defs = mutt_mem_malloc(MT_COLOR_MAX * sizeof(int));
-  memset(Colors->defs, A_NORMAL, sizeof(int) * MT_COLOR_MAX);
+
+  defs_init(Colors);
   Colors->quotes = mutt_mem_malloc(COLOR_QUOTES_MAX * sizeof(int));
   memset(Colors->quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int));
   Colors->quotes_used = 0;
 
-  /* set some defaults */
-  Colors->defs[MT_COLOR_STATUS] = A_REVERSE;
-  Colors->defs[MT_COLOR_INDICATOR] = A_REVERSE;
-  Colors->defs[MT_COLOR_SEARCH] = A_REVERSE;
-  Colors->defs[MT_COLOR_MARKERS] = A_REVERSE;
-#ifdef USE_SIDEBAR
-  Colors->defs[MT_COLOR_SIDEBAR_HIGHLIGHT] = A_UNDERLINE;
-#endif
-  /* special meaning: toggle the relevant attribute */
-  Colors->defs[MT_COLOR_BOLD] = 0;
-  Colors->defs[MT_COLOR_UNDERLINE] = 0;
-
 #ifdef HAVE_COLOR
   start_color();
 #endif
@@ -1229,5 +1263,7 @@ void mutt_colors_free(void)
     cl = next;
   }
   Colors->user_colors = NULL;
+  colors_clear(Colors);
+  defs_free(Colors);
   FREE(&Colors);
 }