Add a kill command that kills the current session

Fixes #331
A given session can be killed with 'echo kill | kak -p <session>'
This commit is contained in:
Maxime Coste 2015-08-26 19:34:19 +01:00
parent 0c41c14187
commit 04536657d1
4 changed files with 30 additions and 7 deletions

View File

@ -13,7 +13,12 @@ namespace Kakoune
{ {
ClientManager::ClientManager() = default; ClientManager::ClientManager() = default;
ClientManager::~ClientManager() = default; ClientManager::~ClientManager()
{
// So that clients destructor find the client manager empty
// so that local UI does not fork.
ClientList clients = std::move(m_clients);
}
String ClientManager::generate_name() const String ClientManager::generate_name() const
{ {

View File

@ -263,6 +263,17 @@ const CommandDesc writeall_cmd = {
[](const ParametersParser&, Context&){ write_all_buffers(); } [](const ParametersParser&, Context&){ write_all_buffers(); }
}; };
const CommandDesc kill_cmd = {
"kill",
nullptr,
"kill current session, quit all clients and server",
no_params,
CommandFlags::None,
CommandHelper{},
CommandCompleter{},
[](const ParametersParser&, Context&){ throw kill_session{}; }
};
template<bool force> template<bool force>
void quit() void quit()
{ {
@ -1649,6 +1660,7 @@ void register_commands()
register_command(writeall_cmd); register_command(writeall_cmd);
register_command(writeall_quit_cmd); register_command(writeall_quit_cmd);
register_command(quit_cmd); register_command(quit_cmd);
register_command(kill_cmd);
register_command(force_quit_cmd); register_command(force_quit_cmd);
register_command(write_quit_cmd); register_command(write_quit_cmd);
register_command(force_write_quit_cmd); register_command(force_write_quit_cmd);

View File

@ -12,6 +12,8 @@ class Key;
void register_commands(); void register_commands();
void exec_keys(ConstArrayView<Key> keys, Context& context); void exec_keys(ConstArrayView<Key> keys, Context& context);
struct kill_session {};
} }
#endif // commands_hh_INCLUDED #endif // commands_hh_INCLUDED

View File

@ -450,14 +450,18 @@ int run_server(StringView session, StringView init_command,
if (not daemon) if (not daemon)
create_local_client(create_local_ui(dummy_ui), init_command, startup_error); create_local_client(create_local_ui(dummy_ui), init_command, startup_error);
while (not terminate and (not client_manager.empty() or daemon)) try
{ {
client_manager.redraw_clients(); while (not terminate and (not client_manager.empty() or daemon))
event_manager.handle_next_events(EventMode::Normal); {
client_manager.handle_pending_inputs(); client_manager.redraw_clients();
buffer_manager.clear_buffer_trash(); event_manager.handle_next_events(EventMode::Normal);
string_registry.purge_unused(); client_manager.handle_pending_inputs();
buffer_manager.clear_buffer_trash();
string_registry.purge_unused();
}
} }
catch (const kill_session&) {}
{ {
Context empty_context{Context::EmptyContextFlag{}}; Context empty_context{Context::EmptyContextFlag{}};