Code

plugin: call g_io_channel_unref() early, eliminate "channel" attribute
[ncmpc.git] / src / colors.c
index 361a7e93d16f000be78b2aa53222a67c4046814a..0c79e13d57d56e72b616cde344032e13efe29b9a 100644 (file)
@@ -1,24 +1,26 @@
 /* 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
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
-
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
-
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+ */
 
 #include "colors.h"
 #include "i18n.h"
+#include "ncfix.h"
+
 #ifdef ENABLE_COLORS
 #include "options.h"
 #endif
@@ -51,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},
@@ -70,9 +73,7 @@ static GList *color_definition_list = NULL;
 static color_entry_t *
 colors_lookup_by_name(const char *name)
 {
-       enum color i;
-
-       for (i = 1; i < COLOR_END; ++i)
+       for (enum color i = 1; i < COLOR_END; ++i)
                if (!strcasecmp(colors[i].name, name))
                        return &colors[i];
 
@@ -82,12 +83,10 @@ colors_lookup_by_name(const char *name)
 static int
 colors_update_pair(enum color id)
 {
-       int fg, bg;
-
        assert(id > 0 && id < COLOR_END);
 
-       fg = colors[id].color;
-       bg = colors[COLOR_BACKGROUND].color;
+       int fg = colors[id].color;
+       int bg = colors[COLOR_BACKGROUND].color;
 
        /* If color == COLOR_NONE (negative),
         * pass -1 to avoid cast errors */
@@ -100,9 +99,9 @@ colors_update_pair(enum color id)
 int
 colors_str2color(const char *str)
 {
-       int i, color = 0;
+       int color = 0;
        char **parts = g_strsplit(str, ",", 0);
-       for (i = 0; parts[i]; i++) {
+       for (int i = 0; parts[i]; i++) {
                char *cur = parts[i];
 
                /* Legacy colors (brightblue,etc) */
@@ -169,13 +168,13 @@ colors_str2color(const char *str)
 int
 colors_define(const char *name, short r, short g, short b)
 {
-       color_definition_entry_t *entry;
        int color = colors_str2color(name);
 
        if (color < 0)
                return color;
 
-       entry = g_malloc(sizeof(color_definition_entry_t));
+       color_definition_entry_t *entry =
+               g_malloc(sizeof(color_definition_entry_t));
        entry->color = color;
        entry->r = r;
        entry->g = g;
@@ -190,14 +189,14 @@ int
 colors_assign(const char *name, const char *value)
 {
        color_entry_t *entry = colors_lookup_by_name(name);
-       int color;
 
        if (!entry) {
                fprintf(stderr,_("Warning: Unknown color field - %s\n"), name);
                return -1;
        }
 
-       if ((color = colors_str2color(value)) == COLOR_ERROR)
+       const int color = colors_str2color(value);
+       if (color == COLOR_ERROR)
                return -1;
 
        entry->color = color;
@@ -229,9 +228,7 @@ colors_start(void)
                                _("Terminal lacks support for changing colors"));
 
                if (options.enable_colors) {
-                       enum color i;
-
-                       for (i = 1; i < COLOR_END; ++i)
+                       for (enum color i = 1; i < COLOR_END; ++i)
                                /* update the color pairs */
                                colors_update_pair(i);
                }
@@ -262,12 +259,12 @@ int
 colors_use(WINDOW *w, enum color id)
 {
        color_entry_t *entry = &colors[id];
-       short pair;
-       attr_t attrs;
 
        assert(id > 0 && id < COLOR_END);
 
-       wattr_get(w, &attrs, &pair, NULL);
+       attr_t attrs;
+       short pair;
+       fix_wattr_get(w, &attrs, &pair, NULL);
 
 #ifdef ENABLE_COLORS
        if (options.enable_colors) {