2012-09-17 19:01:13 +02:00
|
|
|
#include "color_registry.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
const ColorPair& ColorRegistry::operator[](const String& colordesc)
|
|
|
|
{
|
|
|
|
auto alias_it = m_aliases.find(colordesc);
|
|
|
|
if (alias_it != m_aliases.end())
|
|
|
|
return alias_it->second;
|
|
|
|
|
|
|
|
auto it = std::find(colordesc.begin(), colordesc.end(), ',');
|
2013-03-25 23:35:59 +01:00
|
|
|
ColorPair colpair{ str_to_color(String(colordesc.begin(), it)),
|
2012-09-17 19:01:13 +02:00
|
|
|
it != colordesc.end() ?
|
2013-03-25 23:35:59 +01:00
|
|
|
str_to_color(String(it+1, colordesc.end()))
|
2012-09-17 19:01:13 +02:00
|
|
|
: Color::Default };
|
|
|
|
|
2012-10-11 01:17:29 +02:00
|
|
|
return (m_aliases[colordesc] = colpair);
|
2012-09-17 19:01:13 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 21:01:11 +02:00
|
|
|
void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
|
|
|
bool override)
|
2012-09-17 19:01:13 +02:00
|
|
|
{
|
2012-09-17 21:01:11 +02:00
|
|
|
if (not override and m_aliases.find(name) != m_aliases.end())
|
2012-09-17 19:01:13 +02:00
|
|
|
throw runtime_error("alias '" + name + "' already defined");
|
|
|
|
|
|
|
|
if (std::find_if(name.begin(), name.end(),
|
2012-10-08 19:33:53 +02:00
|
|
|
[](char c) { return not isalnum(c); }) != name.end())
|
2012-09-17 19:01:13 +02:00
|
|
|
throw runtime_error("alias names are limited to alpha numeric words");
|
|
|
|
|
|
|
|
auto it = std::find(colordesc.begin(), colordesc.end(), ',');
|
2013-03-25 23:35:59 +01:00
|
|
|
auto fg = str_to_color(String(colordesc.begin(), it));
|
2012-09-17 19:01:13 +02:00
|
|
|
auto bg = Color::Default;
|
|
|
|
if (it != colordesc.end())
|
2013-03-25 23:35:59 +01:00
|
|
|
bg = str_to_color(String(it+1, colordesc.end()));
|
2012-09-17 19:01:13 +02:00
|
|
|
|
|
|
|
m_aliases[name] = { fg, bg };
|
|
|
|
}
|
|
|
|
|
2013-03-06 20:31:07 +01:00
|
|
|
ColorRegistry::ColorRegistry()
|
|
|
|
: m_aliases{
|
|
|
|
{ "PrimarySelection", { Color::Cyan, Color::Blue } },
|
|
|
|
{ "SecondarySelection", { Color::Black, Color::Blue } },
|
|
|
|
{ "PrimaryCursor", { Color::Black, Color::White } },
|
|
|
|
{ "SecondaryCursor", { Color::Black, Color::White } },
|
|
|
|
{ "LineNumbers", { Color::Black, Color::White } },
|
2013-04-04 13:53:47 +02:00
|
|
|
{ "MenuForeground", { Color::Blue, Color::Cyan } },
|
|
|
|
{ "MenuBackground", { Color::Cyan, Color::Blue } },
|
2013-04-04 14:03:40 +02:00
|
|
|
{ "Information", { Color::Black, Color::Yellow } },
|
2013-04-04 18:50:00 +02:00
|
|
|
{ "Error", { Color::Black, Color::Red } },
|
|
|
|
{ "StatusLine", { Color::Cyan, Color::Default } },
|
|
|
|
{ "StatusCursor", { Color::Black, Color::Cyan } },
|
2013-04-06 13:07:04 +02:00
|
|
|
{ "Prompt", { Color::Yellow, Color::Default} },
|
2013-03-06 20:31:07 +01:00
|
|
|
}
|
|
|
|
{}
|
|
|
|
|
2012-09-17 19:01:13 +02:00
|
|
|
}
|