2014-07-11 01:27:04 +02:00
|
|
|
#include "face_registry.hh"
|
2012-09-17 19:01:13 +02:00
|
|
|
|
|
|
|
#include "exception.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
static Face parse_face(const String& facedesc)
|
2012-09-17 19:01:13 +02:00
|
|
|
{
|
2014-07-11 01:27:04 +02:00
|
|
|
auto it = std::find(facedesc.begin(), facedesc.end(), ',');
|
|
|
|
return { str_to_color({facedesc.begin(), it}),
|
|
|
|
it != facedesc.end() ? str_to_color({it+1, facedesc.end()})
|
2013-05-15 14:01:23 +02:00
|
|
|
: Colors::Default };
|
|
|
|
}
|
2012-09-17 19:01:13 +02:00
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
const Face& FaceRegistry::operator[](const String& facedesc)
|
2013-05-15 14:01:23 +02:00
|
|
|
{
|
2014-07-11 01:27:04 +02:00
|
|
|
auto it = m_aliases.find(facedesc);
|
2013-05-15 14:01:23 +02:00
|
|
|
if (it != m_aliases.end())
|
|
|
|
return it->second;
|
2014-07-11 01:27:04 +02:00
|
|
|
return (m_aliases[facedesc] = parse_face(facedesc));
|
2012-09-17 19:01:13 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
void FaceRegistry::register_alias(const String& name, const String& facedesc,
|
2012-09-17 21:01:11 +02:00
|
|
|
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())
|
2013-12-03 20:48:53 +01:00
|
|
|
throw runtime_error("alias '" + name + "' already defined");
|
2012-09-17 19:01:13 +02:00
|
|
|
|
2013-05-15 14:01:23 +02: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 19:01:13 +02:00
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
auto it = m_aliases.find(facedesc);
|
2013-05-15 14:01:23 +02:00
|
|
|
m_aliases[name] = (it != m_aliases.end()) ?
|
2014-07-11 01:27:04 +02:00
|
|
|
it->second : parse_face(facedesc);
|
2012-09-17 19:01:13 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
CandidateList FaceRegistry::complete_alias_name(StringView prefix,
|
2014-03-29 14:18:46 +01:00
|
|
|
ByteCount cursor_pos) const
|
|
|
|
{
|
|
|
|
CandidateList res;
|
2014-04-18 15:02:14 +02:00
|
|
|
auto real_prefix = prefix.substr(0, cursor_pos);
|
2014-03-29 14:18:46 +01:00
|
|
|
for (auto& alias : m_aliases)
|
|
|
|
{
|
|
|
|
if (prefix_match(alias.first, real_prefix))
|
|
|
|
res.push_back(alias.first);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
FaceRegistry::FaceRegistry()
|
2013-03-06 20:31:07 +01:00
|
|
|
: 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 } },
|
2013-05-24 18:39:03 +02:00
|
|
|
{ "LineNumbers", { Colors::Default, Colors::Default } },
|
2014-03-29 09:54:45 +01:00
|
|
|
{ "MenuForeground", { Colors::White, Colors::Blue } },
|
|
|
|
{ "MenuBackground", { Colors::Blue, Colors::White } },
|
2013-05-07 18:52:23 +02:00
|
|
|
{ "Information", { Colors::Black, Colors::Yellow } },
|
|
|
|
{ "Error", { Colors::Black, Colors::Red } },
|
|
|
|
{ "StatusLine", { Colors::Cyan, Colors::Default } },
|
|
|
|
{ "StatusCursor", { Colors::Black, Colors::Cyan } },
|
2014-01-20 22:01:26 +01:00
|
|
|
{ "Prompt", { Colors::Yellow, Colors::Default } },
|
|
|
|
{ "MatchingChar", { Colors::Default, Colors::Magenta } },
|
2014-05-13 20:35:28 +02:00
|
|
|
{ "Search", { Colors::Default, Colors::Magenta } },
|
2013-03-06 20:31:07 +01:00
|
|
|
}
|
|
|
|
{}
|
|
|
|
|
2012-09-17 19:01:13 +02:00
|
|
|
}
|