code style cleanup in CommandManager
This commit is contained in:
parent
7bcd0353cb
commit
73c446e379
|
@ -16,19 +16,19 @@ bool CommandManager::command_defined(const String& command_name) const
|
||||||
return m_commands.find(command_name) != m_commands.end();
|
return m_commands.find(command_name) != m_commands.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandManager::register_command(const String& command_name,
|
void CommandManager::register_command(String command_name,
|
||||||
Command command,
|
Command command,
|
||||||
const CommandCompleter& completer)
|
CommandCompleter completer)
|
||||||
{
|
{
|
||||||
m_commands[command_name] = CommandDescriptor { command, completer };
|
m_commands[command_name] = { std::move(command), std::move(completer) };
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandManager::register_commands(const memoryview<String>& command_names,
|
void CommandManager::register_commands(const memoryview<String>& command_names,
|
||||||
Command command,
|
Command command,
|
||||||
const CommandCompleter& completer)
|
CommandCompleter completer)
|
||||||
{
|
{
|
||||||
for (auto command_name : command_names)
|
for (auto command_name : command_names)
|
||||||
register_command(command_name, command, completer);
|
m_commands[command_name] = { command, completer };
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_error::parse_error(const String& error)
|
parse_error::parse_error(const String& error)
|
||||||
|
|
|
@ -14,28 +14,25 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Context;
|
|
||||||
|
|
||||||
struct parse_error : runtime_error
|
struct parse_error : runtime_error
|
||||||
{
|
{
|
||||||
parse_error(const String& error);
|
parse_error(const String& error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Context;
|
||||||
using CommandParameters = memoryview<String>;
|
using CommandParameters = memoryview<String>;
|
||||||
|
using Command = std::function<void (const CommandParameters&,
|
||||||
typedef std::function<void (const CommandParameters&,
|
Context& context)>;
|
||||||
Context& context)> Command;
|
using CommandCompleter = std::function<CandidateList (const Context& context,
|
||||||
|
|
||||||
typedef std::function<CandidateList (const Context& context,
|
|
||||||
const CommandParameters&,
|
const CommandParameters&,
|
||||||
size_t, ByteCount)> CommandCompleter;
|
size_t, ByteCount)>;
|
||||||
|
|
||||||
class PerArgumentCommandCompleter
|
class PerArgumentCommandCompleter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::function<CandidateList (const Context&,
|
using ArgumentCompleter = std::function<CandidateList (const Context&,
|
||||||
const String&, ByteCount)> ArgumentCompleter;
|
const String&, ByteCount)>;
|
||||||
typedef memoryview<ArgumentCompleter> ArgumentCompleterList;
|
using ArgumentCompleterList = memoryview<ArgumentCompleter>;
|
||||||
|
|
||||||
PerArgumentCommandCompleter(const ArgumentCompleterList& completers)
|
PerArgumentCommandCompleter(const ArgumentCompleterList& completers)
|
||||||
: m_completers(completers.begin(), completers.end()) {}
|
: m_completers(completers.begin(), completers.end()) {}
|
||||||
|
@ -61,13 +58,13 @@ public:
|
||||||
|
|
||||||
bool command_defined(const String& command_name) const;
|
bool command_defined(const String& command_name) const;
|
||||||
|
|
||||||
void register_command(const String& command_name,
|
void register_command(String command_name,
|
||||||
Command command,
|
Command command,
|
||||||
const CommandCompleter& completer = CommandCompleter());
|
CommandCompleter completer = CommandCompleter());
|
||||||
|
|
||||||
void register_commands(const memoryview<String>& command_names,
|
void register_commands(const memoryview<String>& command_names,
|
||||||
Command command,
|
Command command,
|
||||||
const CommandCompleter& completer = CommandCompleter());
|
CommandCompleter completer = CommandCompleter());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void execute_single_command(const CommandParameters& params,
|
void execute_single_command(const CommandParameters& params,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user