CommandManager: now a singleton

This commit is contained in:
Maxime Coste 2011-09-23 14:29:42 +00:00
parent c2cbd69c1a
commit 8f70192875
2 changed files with 11 additions and 9 deletions

View File

@ -7,7 +7,7 @@
#include <functional>
#include <initializer_list>
#include "exception.hh"
#include "utils.hh"
#include "completion.hh"
namespace Kakoune
@ -47,7 +47,7 @@ private:
ArgumentCompleterList m_completers;
};
class CommandManager
class CommandManager : public Singleton<CommandManager>
{
public:
void execute(const std::string& command_line);

View File

@ -329,17 +329,15 @@ void show_buffer(const CommandParameters& params)
current_window = buffer->get_or_create_window();
}
CommandManager command_manager;
BufferManager buffer_manager;
void do_command()
{
try
{
command_manager.execute(prompt(":", std::bind(&CommandManager::complete,
&command_manager,
std::placeholders::_1,
std::placeholders::_2)));
auto cmdline = prompt(":", std::bind(&CommandManager::complete,
&CommandManager::instance(),
_1, _2));
CommandManager::instance().execute(cmdline);
}
catch (prompt_aborted&) {}
}
@ -400,6 +398,10 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
int main(int argc, char* argv[])
{
init_ncurses();
CommandManager command_manager;
BufferManager buffer_manager;
command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit,
PerArgumentCommandCompleter{ complete_filename });
command_manager.register_command(std::vector<std::string>{ "q", "quit" }, quit);