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()))
|
2013-05-07 18:52:23 +02:00
|
|
|
: Colors::Default };
|
2012-09-17 19:01:13 +02:00
|
|
|
|
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));
|
2013-05-07 18:52:23 +02:00
|
|
|
auto bg = Color{Colors::Default};
|
2012-09-17 19:01:13 +02:00
|
|
|
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{
|
2013-05-07 18:52:23 +02:00
|
|
|
{ "PrimarySelection", { Colors::Cyan, Colors::Blue } },
|
|
|
|
{ "SecondarySelection", { Colors::Black, Colors::Blue } },
|
|
|
|
{ "PrimaryCursor", { Colors::Black, Colors::White } },
|
|
|
|
{ "SecondaryCursor", { Colors::Black, Colors::White } },
|
|
|
|
{ "LineNumbers", { Colors::Black, Colors::White } },
|
|
|
|
{ "MenuForeground", { Colors::Blue, Colors::Cyan } },
|
|
|
|
{ "MenuBackground", { Colors::Cyan, Colors::Blue } },
|
|
|
|
{ "Information", { Colors::Black, Colors::Yellow } },
|
|
|
|
{ "Error", { Colors::Black, Colors::Red } },
|
|
|
|
{ "StatusLine", { Colors::Cyan, Colors::Default } },
|
|
|
|
{ "StatusCursor", { Colors::Black, Colors::Cyan } },
|
|
|
|
{ "Prompt", { Colors::Yellow, Colors::Default} },
|
2013-03-06 20:31:07 +01:00
|
|
|
}
|
|
|
|
{}
|
|
|
|
|
2012-09-17 19:01:13 +02:00
|
|
|
}
|