mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-29 14:44:56 +03:00
colalias can reference another alias
This commit is contained in:
parent
1fb971e389
commit
ef7d90cbfa
@ -5,19 +5,20 @@
|
||||
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)
|
||||
{
|
||||
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(), ',');
|
||||
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);
|
||||
auto it = m_aliases.find(colordesc);
|
||||
if (it != m_aliases.end())
|
||||
return it->second;
|
||||
return (m_aliases[colordesc] = parse_color_pair(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())
|
||||
throw runtime_error("alias '" + name + "' already defined");
|
||||
|
||||
if (std::find_if(name.begin(), name.end(),
|
||||
[](char c) { return not isalnum(c); }) != name.end())
|
||||
throw runtime_error("alias names are limited to alpha numeric words");
|
||||
if (name.empty() or
|
||||
find_if(name, [](char c){ return not isalnum(c); }) != name.end())
|
||||
throw runtime_error("invalid alias name");
|
||||
|
||||
auto it = std::find(colordesc.begin(), colordesc.end(), ',');
|
||||
auto fg = str_to_color(String(colordesc.begin(), it));
|
||||
auto bg = Color{Colors::Default};
|
||||
if (it != colordesc.end())
|
||||
bg = str_to_color(String(it+1, colordesc.end()));
|
||||
|
||||
m_aliases[name] = { fg, bg };
|
||||
auto it = m_aliases.find(colordesc);
|
||||
m_aliases[name] = (it != m_aliases.end()) ?
|
||||
it->second : parse_color_pair(colordesc);
|
||||
}
|
||||
|
||||
ColorRegistry::ColorRegistry()
|
||||
|
Loading…
Reference in New Issue
Block a user