Code

colors: return bool instead of int
[ncmpc.git] / src / colors.c
index 449d372777686d5ee38acb34634ad99de77b4340..3b100bc22f3c06ea30614b69a48d0710a133f44d 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
+ * (c) 2004-2017 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
  *
  * This program is free software; you can redistribute it and/or modify
@@ -53,6 +53,7 @@ static color_entry_t colors[COLOR_END] = {
        [COLOR_TITLE_BOLD]   = {"title-bold",        COLOR_YELLOW | A_BOLD, A_BOLD  },
        [COLOR_LINE]         = {"line",              COLOR_WHITE,           A_NORMAL},
        [COLOR_LINE_BOLD]    = {"line-bold",         COLOR_WHITE  | A_BOLD, A_BOLD  },
+       [COLOR_LINE_FLAGS]   = {"line-flags",        COLOR_YELLOW,          A_NORMAL},
        [COLOR_LIST]         = {"list",              COLOR_GREEN,           A_NORMAL},
        [COLOR_LIST_BOLD]    = {"list-bold",         COLOR_GREEN  | A_BOLD, A_BOLD  },
        [COLOR_PROGRESSBAR]  = {"progressbar",       COLOR_WHITE,           A_NORMAL},
@@ -79,7 +80,7 @@ colors_lookup_by_name(const char *name)
        return NULL;
 }
 
-static int
+static void
 colors_update_pair(enum color id)
 {
        assert(id > 0 && id < COLOR_END);
@@ -92,7 +93,6 @@ colors_update_pair(enum color id)
        init_pair(id,
                (fg < 0 ? -1 : fg),
                (bg < 0 ? -1 : bg));
-       return 0;
 }
 
 int
@@ -151,7 +151,8 @@ colors_str2color(const char *str)
                        if (cur != endptr && endptr[0] == '\0') {
                                color |= tmp;
                        } else {
-                               fprintf(stderr,_("Warning: Unknown color - %s\n"), str);
+                               fprintf(stderr, "%s: %s\n",
+                                       _("Unknown color"), str);
                                return COLOR_ERROR;
                        }
                }
@@ -164,13 +165,13 @@ colors_str2color(const char *str)
 /* This function is called from conf.c before curses have been started,
  * it adds the definition to the color_definition_list and init_color() is
  * done in colors_start() */
-int
+bool
 colors_define(const char *name, short r, short g, short b)
 {
        int color = colors_str2color(name);
 
        if (color < 0)
-               return color;
+               return false;
 
        color_definition_entry_t *entry =
                g_malloc(sizeof(color_definition_entry_t));
@@ -181,29 +182,29 @@ colors_define(const char *name, short r, short g, short b)
 
        color_definition_list = g_list_append(color_definition_list, entry);
 
-       return 0;
+       return true;
 }
 
-int
+bool
 colors_assign(const char *name, const char *value)
 {
        color_entry_t *entry = colors_lookup_by_name(name);
 
        if (!entry) {
-               fprintf(stderr,_("Warning: Unknown color field - %s\n"), name);
-               return -1;
+               fprintf(stderr, "%s: %s",
+                       _("Unknown color field"), name);
+               return false;
        }
 
        const int color = colors_str2color(value);
        if (color == COLOR_ERROR)
-               return -1;
+               return false;
 
        entry->color = color;
-       return 0;
+       return true;
 }
 
-
-int
+void
 colors_start(void)
 {
        if (has_colors()) {
@@ -249,12 +250,10 @@ colors_start(void)
                g_list_free(color_definition_list);
                color_definition_list = NULL;
        }
-
-       return 0;
 }
 #endif
 
-int
+void
 colors_use(WINDOW *w, enum color id)
 {
        color_entry_t *entry = &colors[id];
@@ -278,6 +277,4 @@ colors_use(WINDOW *w, enum color id)
 #ifdef ENABLE_COLORS
        }
 #endif
-
-       return 0;
 }