2012-09-17 21:01:13 +04:00
|
|
|
#include "color_registry.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2013-05-15 16:01:23 +04:00
|
|
|
static ColorPair parse_color_pair(const String& colordesc)
|
2012-09-17 21:01:13 +04:00
|
|
|
{
|
|
|
|
auto it = std::find(colordesc.begin(), colordesc.end(), ',');
|
2013-05-15 16:01:23 +04:00
|
|
|
return { str_to_color({colordesc.begin(), it}),
|
|
|
|
it != colordesc.end() ? str_to_color({it+1, colordesc.end()})
|
|
|
|
: Colors::Default };
|
|
|
|
}
|
2012-09-17 21:01:13 +04:00
|
|
|
|
2013-05-15 16:01:23 +04:00
|
|
|
const ColorPair& ColorRegistry::operator[](const String& colordesc)
|
|
|
|
{
|
|
|
|
auto it = m_aliases.find(colordesc);
|
|
|
|
if (it != m_aliases.end())
|
|
|
|
return it->second;
|
|
|
|
return (m_aliases[colordesc] = parse_color_pair(colordesc));
|
2012-09-17 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
2012-09-17 23:01:11 +04:00
|
|
|
void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
|
|
|
bool override)
|
2012-09-17 21:01:13 +04:00
|
|
|
{
|
2012-09-17 23:01:11 +04:00
|
|
|
if (not override and m_aliases.find(name) != m_aliases.end())
|
2013-12-03 23:48:53 +04:00
|
|
|
throw runtime_error("alias '" + name + "' already defined");
|
2012-09-17 21:01:13 +04:00
|
|
|
|
2013-05-15 16:01:23 +04:00
|
|
|
if (name.empty() or
|
|
|
|
find_if(name, [](char c){ return not isalnum(c); }) != name.end())
|
|
|
|
throw runtime_error("invalid alias name");
|
2012-09-17 21:01:13 +04:00
|
|
|
|
2013-05-15 16:01:23 +04:00
|
|
|
auto it = m_aliases.find(colordesc);
|
|
|
|
m_aliases[name] = (it != m_aliases.end()) ?
|
|
|
|
it->second : parse_color_pair(colordesc);
|
2012-09-17 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
2014-04-18 17:02:14 +04:00
|
|
|
CandidateList ColorRegistry::complete_alias_name(StringView prefix,
|
2014-03-29 17:18:46 +04:00
|
|
|
ByteCount cursor_pos) const
|
|
|
|
{
|
|
|
|
CandidateList res;
|
2014-04-18 17:02:14 +04:00
|
|
|
auto real_prefix = prefix.substr(0, cursor_pos);
|
2014-03-29 17:18:46 +04:00
|
|
|
for (auto& alias : m_aliases)
|
|
|
|
{
|
|
|
|
if (prefix_match(alias.first, real_prefix))
|
|
|
|
res.push_back(alias.first);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-03-06 23:31:07 +04:00
|
|
|
ColorRegistry::ColorRegistry()
|
|
|
|
: m_aliases{
|
2013-05-07 20:52:23 +04:00
|
|
|
{ "PrimarySelection", { Colors::Cyan, Colors::Blue } },
|
|
|
|
{ "SecondarySelection", { Colors::Black, Colors::Blue } },
|
|
|
|
{ "PrimaryCursor", { Colors::Black, Colors::White } },
|
|
|
|
{ "SecondaryCursor", { Colors::Black, Colors::White } },
|
2013-05-24 20:39:03 +04:00
|
|
|
{ "LineNumbers", { Colors::Default, Colors::Default } },
|
2014-03-29 12:54:45 +04:00
|
|
|
{ "MenuForeground", { Colors::White, Colors::Blue } },
|
|
|
|
{ "MenuBackground", { Colors::Blue, Colors::White } },
|
2013-05-07 20:52:23 +04:00
|
|
|
{ "Information", { Colors::Black, Colors::Yellow } },
|
|
|
|
{ "Error", { Colors::Black, Colors::Red } },
|
|
|
|
{ "StatusLine", { Colors::Cyan, Colors::Default } },
|
|
|
|
{ "StatusCursor", { Colors::Black, Colors::Cyan } },
|
2014-01-21 01:01:26 +04:00
|
|
|
{ "Prompt", { Colors::Yellow, Colors::Default } },
|
|
|
|
{ "MatchingChar", { Colors::Default, Colors::Magenta } },
|
2014-05-13 22:35:28 +04:00
|
|
|
{ "Search", { Colors::Default, Colors::Magenta } },
|
2013-03-06 23:31:07 +04:00
|
|
|
}
|
|
|
|
{}
|
|
|
|
|
2012-09-17 21:01:13 +04:00
|
|
|
}
|