window: add support for textual representation of background color
This commit is contained in:
@@ -58,8 +58,11 @@ std::pair<std::vector<Column>, std::string> generate_columns(const std::string &
|
|||||||
while (!(width = getEnclosedString(format, '(', ')', &pos)).empty())
|
while (!(width = getEnclosedString(format, '(', ')', &pos)).empty())
|
||||||
{
|
{
|
||||||
Column col;
|
Column col;
|
||||||
col.color = stringToColor(getEnclosedString(format, '[', ']', &pos));
|
auto scolor = getEnclosedString(format, '[', ']', &pos);
|
||||||
std::string tag_type = getEnclosedString(format, '{', '}', &pos);
|
if (scolor.empty())
|
||||||
|
col.color = NC::Color::Default;
|
||||||
|
else
|
||||||
|
col.color = boost::lexical_cast<NC::Color>(scolor);
|
||||||
|
|
||||||
if (*width.rbegin() == 'f')
|
if (*width.rbegin() == 'f')
|
||||||
{
|
{
|
||||||
@@ -69,6 +72,7 @@ std::pair<std::vector<Column>, std::string> generate_columns(const std::string &
|
|||||||
else
|
else
|
||||||
col.fixed = false;
|
col.fixed = false;
|
||||||
|
|
||||||
|
auto tag_type = getEnclosedString(format, '{', '}', &pos);
|
||||||
// alternative name
|
// alternative name
|
||||||
size_t tag_type_colon_pos = tag_type.find(':');
|
size_t tag_type_colon_pos = tag_type.find(':');
|
||||||
if (tag_type_colon_pos != std::string::npos)
|
if (tag_type_colon_pos != std::string::npos)
|
||||||
@@ -243,11 +247,14 @@ bool Configuration::read(const std::string &config_path)
|
|||||||
return result;
|
return result;
|
||||||
}));
|
}));
|
||||||
p.add("visualizer_color", option_parser::worker([this](std::string v) {
|
p.add("visualizer_color", option_parser::worker([this](std::string v) {
|
||||||
boost::sregex_token_iterator i(v.begin(), v.end(), boost::regex("\\w+")), j;
|
boost::sregex_token_iterator color(v.begin(), v.end(), boost::regex("\\w+")), end;
|
||||||
for (; i != j; ++i)
|
for (; color != end; ++color)
|
||||||
{
|
{
|
||||||
auto color = stringToColor(*i);
|
try {
|
||||||
visualizer_colors.push_back(color);
|
visualizer_colors.push_back(boost::lexical_cast<NC::Color>(*color));
|
||||||
|
} catch (boost::bad_lexical_cast &) {
|
||||||
|
throw std::runtime_error("invalid color: " + *color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (visualizer_colors.empty())
|
if (visualizer_colors.empty())
|
||||||
throw std::runtime_error("empty list");
|
throw std::runtime_error("empty list");
|
||||||
|
|||||||
@@ -50,28 +50,6 @@ NC::Color charToColor(char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NC::Color stringToColor(const std::string &color)
|
|
||||||
{
|
|
||||||
NC::Color result = NC::Color::Default;
|
|
||||||
if (color == "black")
|
|
||||||
result = NC::Color::Black;
|
|
||||||
else if (color == "red")
|
|
||||||
result = NC::Color::Red;
|
|
||||||
else if (color == "green")
|
|
||||||
result = NC::Color::Green;
|
|
||||||
else if (color == "yellow")
|
|
||||||
result = NC::Color::Yellow;
|
|
||||||
else if (color == "blue")
|
|
||||||
result = NC::Color::Blue;
|
|
||||||
else if (color == "magenta")
|
|
||||||
result = NC::Color::Magenta;
|
|
||||||
else if (color == "cyan")
|
|
||||||
result = NC::Color::Cyan;
|
|
||||||
else if (color == "white")
|
|
||||||
result = NC::Color::White;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NC::Border stringToBorder(const std::string &border)
|
NC::Border stringToBorder(const std::string &border)
|
||||||
{
|
{
|
||||||
NC::Border result = NC::Border::None;
|
NC::Border result = NC::Border::None;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
NC::Color charToColor(char c);
|
NC::Color charToColor(char c);
|
||||||
|
|
||||||
NC::Color stringToColor(const std::string &color);
|
|
||||||
NC::Border stringToBorder(const std::string &border);
|
NC::Border stringToBorder(const std::string &border);
|
||||||
|
|
||||||
std::string tagTypeToString(mpd_tag_type tag);
|
std::string tagTypeToString(mpd_tag_type tag);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -229,38 +230,70 @@ std::ostream &operator<<(std::ostream &os, const Color &c)
|
|||||||
else if (c == Color::White)
|
else if (c == Color::White)
|
||||||
os << "white";
|
os << "white";
|
||||||
else if (c.isEnd())
|
else if (c.isEnd())
|
||||||
os << "color_end";
|
os << "end";
|
||||||
else
|
else
|
||||||
os << "color_" << c.foreground() << "_" << c.background();
|
os << c.foreground() << "_" << c.background();
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream &operator>>(std::istream &is, Color &c)
|
std::istream &operator>>(std::istream &is, Color &c)
|
||||||
{
|
{
|
||||||
|
auto get_single_color = [](const std::string &s) {
|
||||||
|
std::cerr << "s: " << s << "\n";
|
||||||
|
short result = -1;
|
||||||
|
if (s == "black")
|
||||||
|
result = COLOR_BLACK;
|
||||||
|
else if (s == "red")
|
||||||
|
result = COLOR_RED;
|
||||||
|
else if (s == "green")
|
||||||
|
result = COLOR_GREEN;
|
||||||
|
else if (s == "yellow")
|
||||||
|
result = COLOR_YELLOW;
|
||||||
|
else if (s == "blue")
|
||||||
|
result = COLOR_BLUE;
|
||||||
|
else if (s == "magenta")
|
||||||
|
result = COLOR_MAGENTA;
|
||||||
|
else if (s == "cyan")
|
||||||
|
result = COLOR_CYAN;
|
||||||
|
else if (s == "white")
|
||||||
|
result = COLOR_WHITE;
|
||||||
|
else if (std::all_of(s.begin(), s.end(), isdigit))
|
||||||
|
{
|
||||||
|
result = atoi(s.c_str());
|
||||||
|
if (result < 1 || result > 256)
|
||||||
|
result = -1;
|
||||||
|
else
|
||||||
|
--result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
std::string sc;
|
std::string sc;
|
||||||
is >> sc;
|
is >> sc;
|
||||||
if (sc == "default")
|
if (sc == "default")
|
||||||
c = Color::Default;
|
c = Color::Default;
|
||||||
else if (sc == "black")
|
else if (sc == "end")
|
||||||
c = Color::Black;
|
|
||||||
else if (sc == "red")
|
|
||||||
c = Color::Red;
|
|
||||||
else if (sc == "green")
|
|
||||||
c = Color::Green;
|
|
||||||
else if (sc == "yellow")
|
|
||||||
c = Color::Yellow;
|
|
||||||
else if (sc == "blue")
|
|
||||||
c = Color::Blue;
|
|
||||||
else if (sc == "magenta")
|
|
||||||
c = Color::Magenta;
|
|
||||||
else if (sc == "cyan")
|
|
||||||
c = Color::Cyan;
|
|
||||||
else if (sc == "white")
|
|
||||||
c = Color::White;
|
|
||||||
else if (sc == "color_end")
|
|
||||||
c = Color::End;
|
c = Color::End;
|
||||||
else
|
else
|
||||||
is.setstate(std::ios::failbit);
|
{
|
||||||
|
short value = get_single_color(sc);
|
||||||
|
if (value != -1)
|
||||||
|
c = Color(value);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t underscore = sc.find('_');
|
||||||
|
if (underscore != std::string::npos)
|
||||||
|
{
|
||||||
|
short fg = get_single_color(sc.substr(0, underscore));
|
||||||
|
short bg = get_single_color(sc.substr(underscore+1));
|
||||||
|
if (fg != -1 && bg != -1)
|
||||||
|
c = Color(fg, bg);
|
||||||
|
else
|
||||||
|
is.setstate(std::ios::failbit);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
is.setstate(std::ios::failbit);
|
||||||
|
}
|
||||||
|
}
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user