Add DefaultCommandMap module to define the default command map.

This commit is contained in:
Josh Holtrop 2017-10-24 21:23:32 -04:00
parent 4df3f620f1
commit 25806993f9
4 changed files with 52 additions and 1 deletions

View File

@ -13,8 +13,12 @@ public:
FORWARD_ON_TO_CHAR,
BACK_UP_TO_CHAR,
BACK_ON_TO_CHAR,
DELETE,
DELETE_MOTION,
DELETE_LINE,
DELETE_CHAR,
DELETE_CHAR_BACK,
CHANGE_MOTION,
CHANGE_LINE,
COMMAND_COUNT,
};

View File

@ -0,0 +1,26 @@
#include "DefaultCommandMap.h"
std::shared_ptr<CommandMap> g_DefaultCommandMap;
void DefaultCommandMap::build()
{
g_DefaultCommandMap = std::make_shared<CommandMap>();
CommandMap * dcm = &*g_DefaultCommandMap;
auto motion_map = std::make_shared<CommandMap>();
motion_map->add("t", Command::Motion::FORWARD_UP_TO_CHAR, nullptr, true);
motion_map->add("f", Command::Motion::FORWARD_ON_TO_CHAR, nullptr, true);
motion_map->add("T", Command::Motion::BACK_UP_TO_CHAR, nullptr, true);
motion_map->add("F", Command::Motion::BACK_ON_TO_CHAR, nullptr, true);
dcm->add("t", Command::FORWARD_UP_TO_CHAR, nullptr, true);
dcm->add("f", Command::FORWARD_ON_TO_CHAR, nullptr, true);
dcm->add("T", Command::BACK_UP_TO_CHAR, nullptr, true);
dcm->add("F", Command::BACK_ON_TO_CHAR, nullptr, true);
dcm->add("d", Command::DELETE_MOTION, motion_map, false);
dcm->add("dd", Command::DELETE_LINE, nullptr, false);
dcm->add("x", Command::DELETE_CHAR, nullptr, false);
dcm->add("X", Command::DELETE_CHAR_BACK, nullptr, false);
dcm->add("c", Command::CHANGE_MOTION, motion_map, false);
dcm->add("cc", Command::CHANGE_LINE, nullptr, false);
}

View File

@ -0,0 +1,19 @@
#ifndef DEFAULTCOMMANDMAP_H
#define DEFAULTCOMMANDMAP_H
#include "CommandMap.h"
extern std::shared_ptr<CommandMap> g_DefaultCommandMap;
class DefaultCommandMap
{
public:
static void build();
static std::shared_ptr<CommandMap> get()
{
return g_DefaultCommandMap;
}
};
#endif

View File

@ -3,6 +3,7 @@
#include "Runtime.h"
#include <memory>
#include "System.h"
#include "DefaultCommandMap.h"
int main(int argc, char * argv[])
{
@ -12,6 +13,7 @@ int main(int argc, char * argv[])
}
Runtime::init(System::executable_path().c_str(), APPNAME);
DefaultCommandMap::build();
const char * filename = nullptr;
if (argc > 1)