colalias can reference another alias
This commit is contained in:
parent
1fb971e389
commit
ef7d90cbfa
|
@ -5,19 +5,20 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static ColorPair parse_color_pair(const String& colordesc)
|
||||||
|
{
|
||||||
|
auto it = std::find(colordesc.begin(), colordesc.end(), ',');
|
||||||
|
return { str_to_color({colordesc.begin(), it}),
|
||||||
|
it != colordesc.end() ? str_to_color({it+1, colordesc.end()})
|
||||||
|
: Colors::Default };
|
||||||
|
}
|
||||||
|
|
||||||
const ColorPair& ColorRegistry::operator[](const String& colordesc)
|
const ColorPair& ColorRegistry::operator[](const String& colordesc)
|
||||||
{
|
{
|
||||||
auto alias_it = m_aliases.find(colordesc);
|
auto it = m_aliases.find(colordesc);
|
||||||
if (alias_it != m_aliases.end())
|
if (it != m_aliases.end())
|
||||||
return alias_it->second;
|
return it->second;
|
||||||
|
return (m_aliases[colordesc] = parse_color_pair(colordesc));
|
||||||
auto it = std::find(colordesc.begin(), colordesc.end(), ',');
|
|
||||||
ColorPair colpair{ str_to_color(String(colordesc.begin(), it)),
|
|
||||||
it != colordesc.end() ?
|
|
||||||
str_to_color(String(it+1, colordesc.end()))
|
|
||||||
: Colors::Default };
|
|
||||||
|
|
||||||
return (m_aliases[colordesc] = colpair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
||||||
|
@ -26,17 +27,13 @@ void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
||||||
if (not override and m_aliases.find(name) != m_aliases.end())
|
if (not override and m_aliases.find(name) != m_aliases.end())
|
||||||
throw runtime_error("alias '" + name + "' already defined");
|
throw runtime_error("alias '" + name + "' already defined");
|
||||||
|
|
||||||
if (std::find_if(name.begin(), name.end(),
|
if (name.empty() or
|
||||||
[](char c) { return not isalnum(c); }) != name.end())
|
find_if(name, [](char c){ return not isalnum(c); }) != name.end())
|
||||||
throw runtime_error("alias names are limited to alpha numeric words");
|
throw runtime_error("invalid alias name");
|
||||||
|
|
||||||
auto it = std::find(colordesc.begin(), colordesc.end(), ',');
|
auto it = m_aliases.find(colordesc);
|
||||||
auto fg = str_to_color(String(colordesc.begin(), it));
|
m_aliases[name] = (it != m_aliases.end()) ?
|
||||||
auto bg = Color{Colors::Default};
|
it->second : parse_color_pair(colordesc);
|
||||||
if (it != colordesc.end())
|
|
||||||
bg = str_to_color(String(it+1, colordesc.end()));
|
|
||||||
|
|
||||||
m_aliases[name] = { fg, bg };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorRegistry::ColorRegistry()
|
ColorRegistry::ColorRegistry()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user