Change 'previous' background color to 'current' and add some documentation

This commit is contained in:
Andrzej Rybczak
2017-03-26 10:02:26 +02:00
parent 554895f0f1
commit 55d2f4c70d
4 changed files with 26 additions and 19 deletions

1
NEWS
View File

@@ -15,6 +15,7 @@ ncmpcpp-0.8 (????-??-??)
* Configuration variable 'visualizer_sample_multiplier' was deprecated and will be removed in 0.9. * Configuration variable 'visualizer_sample_multiplier' was deprecated and will be removed in 0.9.
* Wide character version of ncurses is now required. * Wide character version of ncurses is now required.
* Added 'statusbar_time_color' and 'player_state_color' configuration variables for further customization of statusbar. * 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). * 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. * Lyrics and last_fm can now be startup screens and are lockable.
* Action 'update_environment' now also synchronizes status with MPD. * Action 'update_environment' now also synchronizes status with MPD.

View File

@@ -495,6 +495,12 @@
## the bottom of the help screen for list of available colors ## the bottom of the help screen for list of available colors
## and their numerical values. ## 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 ## Moreover, it is possible to attach format information to
## selected color variables by appending to their end a ## selected color variables by appending to their end a
## colon followed by one or more format flags, e.g. black:b ## colon followed by one or more format flags, e.g. black:b
@@ -506,7 +512,7 @@
## alternative_ui_separator_color. ## alternative_ui_separator_color.
## ##
## Note: due to technical limitations of older ncurses ## 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 ## that you'll be able to use only colors with transparent
## background. ## background.
# #

View File

@@ -199,17 +199,17 @@ std::vector<int> color_pair_map;
namespace NC { namespace NC {
const short Color::transparent = -1; const short Color::transparent = -1;
const short Color::previous = -2; const short Color::current = -2;
Color Color::Default(0, 0, true, false); Color Color::Default(0, 0, true, false);
Color Color::Black(COLOR_BLACK, Color::previous); Color Color::Black(COLOR_BLACK, Color::current);
Color Color::Red(COLOR_RED, Color::previous); Color Color::Red(COLOR_RED, Color::current);
Color Color::Green(COLOR_GREEN, Color::previous); Color Color::Green(COLOR_GREEN, Color::current);
Color Color::Yellow(COLOR_YELLOW, Color::previous); Color Color::Yellow(COLOR_YELLOW, Color::current);
Color Color::Blue(COLOR_BLUE, Color::previous); Color Color::Blue(COLOR_BLUE, Color::current);
Color Color::Magenta(COLOR_MAGENTA, Color::previous); Color Color::Magenta(COLOR_MAGENTA, Color::current);
Color Color::Cyan(COLOR_CYAN, Color::previous); Color Color::Cyan(COLOR_CYAN, Color::current);
Color Color::White(COLOR_WHITE, Color::previous); Color Color::White(COLOR_WHITE, Color::current);
Color Color::End(0, 0, false, true); Color Color::End(0, 0, false, true);
int Color::pairNumber() const int Color::pairNumber() const
@@ -219,7 +219,7 @@ int Color::pairNumber() const
throw std::logic_error("'end' doesn't have a corresponding pair number"); throw std::logic_error("'end' doesn't have a corresponding pair number");
else if (!isDefault()) else if (!isDefault())
{ {
if (!previousBackground()) if (!currentBackground())
result = (background() + 1) % COLORS; result = (background() + 1) % COLORS;
result *= 256; result *= 256;
result += foreground() % COLORS; result += foreground() % COLORS;
@@ -270,8 +270,8 @@ std::istream &operator>>(std::istream &is, Color &c)
result = COLOR_WHITE; result = COLOR_WHITE;
else if (background && s == "transparent") else if (background && s == "transparent")
result = NC::Color::transparent; result = NC::Color::transparent;
else if (background && s == "previous") else if (background && s == "current")
result = NC::Color::previous; result = NC::Color::current;
else if (std::all_of(s.begin(), s.end(), isdigit)) else if (std::all_of(s.begin(), s.end(), isdigit))
{ {
result = atoi(s.c_str()); result = atoi(s.c_str());
@@ -313,7 +313,7 @@ std::istream &operator>>(std::istream &is, Color &c)
c = Color(fg, bg); c = Color(fg, bg);
} }
else else
c = Color(fg, NC::Color::previous); c = Color(fg, NC::Color::current);
} }
return is; return is;
} }
@@ -571,7 +571,7 @@ void Window::setColor(Color c)
c = m_base_color; c = m_base_color;
if (c != Color::Default) if (c != Color::Default)
{ {
assert(!c.previousBackground()); assert(!c.currentBackground());
wcolor_set(m_window, c.pairNumber(), nullptr); wcolor_set(m_window, c.pairNumber(), nullptr);
} }
else else
@@ -581,7 +581,7 @@ void Window::setColor(Color c)
void Window::setBaseColor(const Color &color) void Window::setBaseColor(const Color &color)
{ {
if (color.previousBackground()) if (color.currentBackground())
m_base_color = Color(color.foreground(), Color::transparent); m_base_color = Color(color.foreground(), Color::transparent);
else else
m_base_color = color; m_base_color = color;
@@ -1316,7 +1316,7 @@ Window &Window::operator<<(const Color &c)
} }
else else
{ {
if (c.previousBackground()) if (c.currentBackground())
{ {
short background = m_color.isDefault() short background = m_color.isDefault()
? Color::transparent ? Color::transparent

View File

@@ -149,7 +149,7 @@ struct Color
friend struct Window; friend struct Window;
static const short transparent; static const short transparent;
static const short previous; static const short current;
Color() : m_impl(0, 0, true, false) { } Color() : m_impl(0, 0, true, false) { }
Color(short foreground_value, short background_value, Color(short foreground_value, short background_value,
@@ -183,7 +183,7 @@ struct Color
private: private:
short foreground() const { return std::get<0>(m_impl); } short foreground() const { return std::get<0>(m_impl); }
short background() const { return std::get<1>(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<short, short, bool, bool> m_impl; std::tuple<short, short, bool, bool> m_impl;
}; };