CommandManager: now a singleton
This commit is contained in:
parent
c2cbd69c1a
commit
8f70192875
|
@ -7,7 +7,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
#include "exception.hh"
|
#include "utils.hh"
|
||||||
#include "completion.hh"
|
#include "completion.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
|
@ -47,7 +47,7 @@ private:
|
||||||
ArgumentCompleterList m_completers;
|
ArgumentCompleterList m_completers;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CommandManager
|
class CommandManager : public Singleton<CommandManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void execute(const std::string& command_line);
|
void execute(const std::string& command_line);
|
||||||
|
|
16
src/main.cc
16
src/main.cc
|
@ -329,17 +329,15 @@ void show_buffer(const CommandParameters& params)
|
||||||
current_window = buffer->get_or_create_window();
|
current_window = buffer->get_or_create_window();
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandManager command_manager;
|
|
||||||
BufferManager buffer_manager;
|
|
||||||
|
|
||||||
void do_command()
|
void do_command()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command_manager.execute(prompt(":", std::bind(&CommandManager::complete,
|
auto cmdline = prompt(":", std::bind(&CommandManager::complete,
|
||||||
&command_manager,
|
&CommandManager::instance(),
|
||||||
std::placeholders::_1,
|
_1, _2));
|
||||||
std::placeholders::_2)));
|
|
||||||
|
CommandManager::instance().execute(cmdline);
|
||||||
}
|
}
|
||||||
catch (prompt_aborted&) {}
|
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[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
init_ncurses();
|
init_ncurses();
|
||||||
|
|
||||||
|
CommandManager command_manager;
|
||||||
|
BufferManager buffer_manager;
|
||||||
|
|
||||||
command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit,
|
command_manager.register_command(std::vector<std::string>{ "e", "edit" }, edit,
|
||||||
PerArgumentCommandCompleter{ complete_filename });
|
PerArgumentCommandCompleter{ complete_filename });
|
||||||
command_manager.register_command(std::vector<std::string>{ "q", "quit" }, quit);
|
command_manager.register_command(std::vector<std::string>{ "q", "quit" }, quit);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user