From 55d2f4c70d5bac48d28b1de6d3f62405002fc04a Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 26 Mar 2017 10:02:26 +0200 Subject: [PATCH] Change 'previous' background color to 'current' and add some documentation --- NEWS | 1 + doc/config | 8 +++++++- src/curses/window.cpp | 32 ++++++++++++++++---------------- src/curses/window.h | 4 ++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/NEWS b/NEWS index 3c28c398..381b1cd1 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ ncmpcpp-0.8 (????-??-??) * Configuration variable 'visualizer_sample_multiplier' was deprecated and will be removed in 0.9. * Wide character version of ncurses is now required. * Added 'statusbar_time_color' and 'player_state_color' configuration variables for further customization of statusbar. +* Setting foreground color only now preserves current background color. * Format information can now be attached to selected color variables in the configuration file. Because of that variable 'progressbar_boldness' is now deprecated in favor of extended 'progressbar_color' and 'progressbar_elapsed_color' (for more information see example configuration file). * Lyrics and last_fm can now be startup screens and are lockable. * Action 'update_environment' now also synchronizes status with MPD. diff --git a/doc/config b/doc/config index d066a923..85f8a4bb 100644 --- a/doc/config +++ b/doc/config @@ -495,6 +495,12 @@ ## the bottom of the help screen for list of available colors ## and their numerical values. ## +## What is more, there are two special values for the background +## color: "transparent" and "current". The first one explicitly sets +## the background to be transparent, while the second one allows you +## to preserve current background color and change only the foreground +## one. It's used implicitly when background color is not specified. +## ## Moreover, it is possible to attach format information to ## selected color variables by appending to their end a ## colon followed by one or more format flags, e.g. black:b @@ -506,7 +512,7 @@ ## alternative_ui_separator_color. ## ## Note: due to technical limitations of older ncurses -## versionw, if 256 colors are used there is a possibility +## version, if 256 colors are used there is a possibility ## that you'll be able to use only colors with transparent ## background. # diff --git a/src/curses/window.cpp b/src/curses/window.cpp index 17f3ca5c..7fc20eab 100644 --- a/src/curses/window.cpp +++ b/src/curses/window.cpp @@ -199,17 +199,17 @@ std::vector color_pair_map; namespace NC { const short Color::transparent = -1; -const short Color::previous = -2; +const short Color::current = -2; Color Color::Default(0, 0, true, false); -Color Color::Black(COLOR_BLACK, Color::previous); -Color Color::Red(COLOR_RED, Color::previous); -Color Color::Green(COLOR_GREEN, Color::previous); -Color Color::Yellow(COLOR_YELLOW, Color::previous); -Color Color::Blue(COLOR_BLUE, Color::previous); -Color Color::Magenta(COLOR_MAGENTA, Color::previous); -Color Color::Cyan(COLOR_CYAN, Color::previous); -Color Color::White(COLOR_WHITE, Color::previous); +Color Color::Black(COLOR_BLACK, Color::current); +Color Color::Red(COLOR_RED, Color::current); +Color Color::Green(COLOR_GREEN, Color::current); +Color Color::Yellow(COLOR_YELLOW, Color::current); +Color Color::Blue(COLOR_BLUE, Color::current); +Color Color::Magenta(COLOR_MAGENTA, Color::current); +Color Color::Cyan(COLOR_CYAN, Color::current); +Color Color::White(COLOR_WHITE, Color::current); Color Color::End(0, 0, false, true); int Color::pairNumber() const @@ -219,7 +219,7 @@ int Color::pairNumber() const throw std::logic_error("'end' doesn't have a corresponding pair number"); else if (!isDefault()) { - if (!previousBackground()) + if (!currentBackground()) result = (background() + 1) % COLORS; result *= 256; result += foreground() % COLORS; @@ -270,8 +270,8 @@ std::istream &operator>>(std::istream &is, Color &c) result = COLOR_WHITE; else if (background && s == "transparent") result = NC::Color::transparent; - else if (background && s == "previous") - result = NC::Color::previous; + else if (background && s == "current") + result = NC::Color::current; else if (std::all_of(s.begin(), s.end(), isdigit)) { result = atoi(s.c_str()); @@ -313,7 +313,7 @@ std::istream &operator>>(std::istream &is, Color &c) c = Color(fg, bg); } else - c = Color(fg, NC::Color::previous); + c = Color(fg, NC::Color::current); } return is; } @@ -571,7 +571,7 @@ void Window::setColor(Color c) c = m_base_color; if (c != Color::Default) { - assert(!c.previousBackground()); + assert(!c.currentBackground()); wcolor_set(m_window, c.pairNumber(), nullptr); } else @@ -581,7 +581,7 @@ void Window::setColor(Color c) void Window::setBaseColor(const Color &color) { - if (color.previousBackground()) + if (color.currentBackground()) m_base_color = Color(color.foreground(), Color::transparent); else m_base_color = color; @@ -1316,7 +1316,7 @@ Window &Window::operator<<(const Color &c) } else { - if (c.previousBackground()) + if (c.currentBackground()) { short background = m_color.isDefault() ? Color::transparent diff --git a/src/curses/window.h b/src/curses/window.h index d748a1e3..f53fc4b2 100644 --- a/src/curses/window.h +++ b/src/curses/window.h @@ -149,7 +149,7 @@ struct Color friend struct Window; static const short transparent; - static const short previous; + static const short current; Color() : m_impl(0, 0, true, false) { } Color(short foreground_value, short background_value, @@ -183,7 +183,7 @@ struct Color private: short foreground() const { return std::get<0>(m_impl); } short background() const { return std::get<1>(m_impl); } - bool previousBackground() const { return background() == previous; } + bool currentBackground() const { return background() == current; } std::tuple m_impl; };