extract client main to a run_client function
This commit is contained in:
parent
0960ad9a7f
commit
124be2ac2e
39
src/main.cc
39
src/main.cc
|
@ -174,6 +174,25 @@ void signal_handler(int signal)
|
||||||
abort();
|
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)
|
int kakoune(memoryview<String> params)
|
||||||
{
|
{
|
||||||
ParametersParser parser(params, { { "c", true },
|
ParametersParser parser(params, { { "c", true },
|
||||||
|
@ -195,24 +214,9 @@ int kakoune(memoryview<String> params)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
return run_client(parser.option_value("c"), init_command);
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
catch (peer_disconnected&)
|
|
||||||
{
|
|
||||||
fputs("disconnected from server\n", stderr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const bool daemon = parser.has_option("d");
|
const bool daemon = parser.has_option("d");
|
||||||
static bool terminate = false;
|
static bool terminate = false;
|
||||||
if (daemon)
|
if (daemon)
|
||||||
|
@ -308,7 +312,6 @@ int kakoune(memoryview<String> params)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user