some minor cleanups/refactorings in main

This commit is contained in:
Maxime Coste 2012-10-21 13:02:24 +02:00
parent a0cca31dc1
commit 49237a771b

View File

@ -460,9 +460,11 @@ struct Client
: ui(ui), : ui(ui),
input_handler(new InputHandler{}), input_handler(new InputHandler{}),
context(new Context(*input_handler, window, *ui)) {} context(new Context(*input_handler, window, *ui)) {}
Client() {}
}; };
Client create_client(const String& file) Client create_local_client(const String& file)
{ {
Buffer* buffer = nullptr; Buffer* buffer = nullptr;
UserInterface* ui = new NCursesUI{}; UserInterface* ui = new NCursesUI{};
@ -497,20 +499,9 @@ Client create_client(const String& file)
return client; return client;
} }
int main(int argc, char* argv[]) void register_env_vars()
{ {
EventManager event_manager; ShellManager& shell_manager = ShellManager::instance();
GlobalOptionManager option_manager;
GlobalHookManager hook_manager;
ShellManager shell_manager;
CommandManager command_manager;
BufferManager buffer_manager;
RegisterManager register_manager;
HighlighterRegistry highlighter_registry;
FilterRegistry filter_registry;
ColorRegistry color_registry;
run_unit_tests();
shell_manager.register_env_var("bufname", shell_manager.register_env_var("bufname",
[](const String& name, const Context& context) [](const String& name, const Context& context)
@ -527,6 +518,11 @@ int main(int argc, char* argv[])
shell_manager.register_env_var("reg_.+", shell_manager.register_env_var("reg_.+",
[](const String& name, const Context& context) [](const String& name, const Context& context)
{ return RegisterManager::instance()[name[4]].values(context)[0]; }); { return RegisterManager::instance()[name[4]].values(context)[0]; });
}
void register_registers()
{
RegisterManager& register_manager = RegisterManager::instance();
register_manager.register_dynamic_register('%', [](const Context& context) { return std::vector<String>(1, context.buffer().name()); }); register_manager.register_dynamic_register('%', [](const Context& context) { return std::vector<String>(1, context.buffer().name()); });
register_manager.register_dynamic_register('.', [](const Context& context) { return context.editor().selections_content(); }); register_manager.register_dynamic_register('.', [](const Context& context) { return context.editor().selections_content(); });
@ -540,7 +536,25 @@ int main(int argc, char* argv[])
return result; return result;
}); });
} }
}
int main(int argc, char* argv[])
{
EventManager event_manager;
GlobalOptionManager option_manager;
GlobalHookManager hook_manager;
ShellManager shell_manager;
CommandManager command_manager;
BufferManager buffer_manager;
RegisterManager register_manager;
HighlighterRegistry highlighter_registry;
FilterRegistry filter_registry;
ColorRegistry color_registry;
run_unit_tests();
register_env_vars();
register_registers();
register_commands(); register_commands();
register_highlighters(); register_highlighters();
register_filters(); register_filters();
@ -548,7 +562,7 @@ int main(int argc, char* argv[])
write_debug("*** This is the debug buffer, where debug info will be written ***\n"); write_debug("*** This is the debug buffer, where debug info will be written ***\n");
write_debug("utf-8 test: é á ï"); write_debug("utf-8 test: é á ï");
std::vector<Client> clients; Client local_client;
try try
{ {
try try
@ -561,8 +575,7 @@ int main(int argc, char* argv[])
{ {
write_debug("error while parsing kakrc: " + error.description()); write_debug("error while parsing kakrc: " + error.description());
} }
local_client = create_local_client(argc > 1 ? argv[1] : "");
clients.push_back(create_client(argc > 1 ? argv[1] : ""));
while(not quit_requested) while(not quit_requested)
event_manager.handle_next_events(); event_manager.handle_next_events();