From d8747bc1e000d978a9345277a31bad0d02447778 Mon Sep 17 00:00:00 2001 From: Delapouite Date: Thu, 20 Sep 2018 19:01:47 +0200 Subject: [PATCH] Add completion for rename-buffer, rename-client and rename-session --- src/commands.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index e94fe090..c3cf21da 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -157,6 +157,15 @@ static Completions complete_buffer_name(const Context& context, CompletionFlags return { 0, cursor_pos, res }; } +auto make_single_word_completer(std::function func) +{ + return make_completer( + [func](const Context& context, CompletionFlags flags, + const String& prefix, ByteCount cursor_pos) -> Completions { + auto candidate = { func(context) }; + return { 0_byte, cursor_pos, complete(prefix, cursor_pos, candidate) }; }); +} + auto buffer_completer = make_completer(complete_buffer_name); auto other_buffer_completer = make_completer(complete_buffer_name); @@ -673,7 +682,7 @@ const CommandDesc rename_buffer_cmd = { single_param, CommandFlags::None, CommandHelper{}, - CommandCompleter{}, + make_single_word_completer([](const Context& context){ return context.buffer().display_name(); }), [](const ParametersParser& parser, Context& context, const ShellContext&) { if (not context.buffer().set_name(parser[0])) @@ -2120,7 +2129,7 @@ const CommandDesc rename_client_cmd = { single_param, CommandFlags::None, CommandHelper{}, - CommandCompleter{}, + make_single_word_completer([](const Context& context){ return context.name(); }), [](const ParametersParser& parser, Context& context, const ShellContext&) { const String& name = parser[0]; @@ -2196,7 +2205,7 @@ const CommandDesc rename_session_cmd = { single_param, CommandFlags::None, CommandHelper{}, - CommandCompleter{}, + make_single_word_completer([](const Context&){ return Server::instance().session(); }), [](const ParametersParser& parser, Context&, const ShellContext&) { if (not Server::instance().rename_session(parser[0]))