2011-12-20 20:21:11 +01:00
|
|
|
#include "keys.hh"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-01-29 23:49:14 +01:00
|
|
|
static std::unordered_map<std::string, char> keynamemap = {
|
|
|
|
{ "ret", '\n' },
|
|
|
|
{ "space", ' ' },
|
|
|
|
{ "esc", 27 }
|
2011-12-20 20:21:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
KeyList parse_keys(const std::string& str)
|
|
|
|
{
|
|
|
|
KeyList result;
|
|
|
|
for (size_t pos = 0; pos < str.length(); ++pos)
|
|
|
|
{
|
|
|
|
if (str[pos] == '<')
|
|
|
|
{
|
|
|
|
size_t end_pos = pos;
|
|
|
|
while (end_pos < str.length() and str[end_pos] != '>')
|
|
|
|
++end_pos;
|
|
|
|
|
|
|
|
if (end_pos < str.length())
|
|
|
|
{
|
2012-01-29 23:49:14 +01:00
|
|
|
Key::Modifiers modifier = Key::Modifiers::None;
|
|
|
|
|
2011-12-20 20:21:11 +01:00
|
|
|
std::string keyname = str.substr(pos+1, end_pos - pos - 1);
|
2012-01-29 23:49:14 +01:00
|
|
|
if (keyname.length() > 2)
|
|
|
|
{
|
|
|
|
if (tolower(keyname[0]) == 'c' and keyname[1] == '-')
|
|
|
|
{
|
|
|
|
modifier = Key::Modifiers::Control;
|
|
|
|
keyname = keyname.substr(2);
|
|
|
|
}
|
|
|
|
if (tolower(keyname[0]) == 'a' and keyname[1] == '-')
|
|
|
|
{
|
|
|
|
modifier = Key::Modifiers::Control;
|
|
|
|
keyname = keyname.substr(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (keyname.length() == 1)
|
|
|
|
{
|
|
|
|
result.push_back(Key{ modifier, keyname[0] });
|
|
|
|
pos = end_pos;
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-20 20:21:11 +01:00
|
|
|
auto it = keynamemap.find(keyname);
|
|
|
|
if (it != keynamemap.end())
|
|
|
|
{
|
2012-01-29 23:49:14 +01:00
|
|
|
result.push_back(Key{ modifier, it->second });
|
2011-12-20 20:21:11 +01:00
|
|
|
pos = end_pos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.push_back({Key::Modifiers::None, str[pos]});
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|