extract client main to a run_client function

This commit is contained in:
Maxime Coste 2013-09-23 20:28:15 +02:00
parent 0960ad9a7f
commit 124be2ac2e

View File

@ -174,6 +174,25 @@ void signal_handler(int signal)
abort();
}
int run_client(const String& session, const String& init_command)
{
try
{
EventManager event_manager;
auto client = connect_to(session,
std::unique_ptr<UserInterface>{new NCursesUI{}},
init_command);
while (true)
event_manager.handle_next_events();
}
catch (peer_disconnected&)
{
fputs("disconnected from server\n", stderr);
return -1;
}
return 0;
}
int kakoune(memoryview<String> params)
{
ParametersParser parser(params, { { "c", true },
@ -195,24 +214,9 @@ int kakoune(memoryview<String> params)
return -1;
}
}
try
{
EventManager event_manager;
auto client = connect_to(parser.option_value("c"),
std::unique_ptr<UserInterface>{new NCursesUI{}},
init_command);
while (true)
event_manager.handle_next_events();
return run_client(parser.option_value("c"), init_command);
}
catch (peer_disconnected&)
{
fputs("disconnected from server\n", stderr);
return -1;
}
return 0;
}
else
{
const bool daemon = parser.has_option("d");
static bool terminate = false;
if (daemon)
@ -307,7 +311,6 @@ int kakoune(memoryview<String> params)
global_hooks.run_hook("KakEnd", "", empty_context);
}
return 0;
}
}
int main(int argc, char* argv[])