From 06d0afbef96104c615b309f38775ee41347d808f Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 12 Oct 2016 18:35:15 +0200 Subject: [PATCH] completion to console class (nw) --- src/frontend/mame/console.cpp | 25 ++++++++++++++----------- src/frontend/mame/console.h | 3 +++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/frontend/mame/console.cpp b/src/frontend/mame/console.cpp index aa93a767ace..a1cf5c30f5e 100644 --- a/src/frontend/mame/console.cpp +++ b/src/frontend/mame/console.cpp @@ -16,7 +16,7 @@ #include #include - +static console_frontend *gConsole = nullptr; //------------------------------------------------- // console_frontend - constructor //------------------------------------------------- @@ -31,6 +31,7 @@ console_frontend::console_frontend(emu_options &options, osd_interface &osd) using namespace std::placeholders; m_commands.insert(std::make_pair("quit", std::bind(&console_frontend::cmd_quit, this, _1))); m_commands.insert(std::make_pair("exit", std::bind(&console_frontend::cmd_quit, this, _1))); + gConsole = this; } @@ -42,16 +43,13 @@ console_frontend::~console_frontend() { } -static const char* commandList[] = { - "quit", "exit", NULL -}; - -void completionHook(char const* prefix, linenoiseCompletions* lc) { - size_t i; - - for (i = 0; commandList[i] != NULL; ++i) { - if (strncmp(prefix, commandList[i], strlen(prefix)) == 0) { - linenoiseAddCompletion(lc, commandList[i]); +void console_frontend::completion(char const* prefix, linenoiseCompletions* lc) +{ + for (auto cmd : m_commands) + { + if (strncmp(prefix, cmd.first.c_str(), strlen(prefix)) == 0) + { + linenoiseAddCompletion(lc, cmd.first.c_str()); } } } @@ -131,6 +129,11 @@ void console_frontend::split_command(std::vector& arg, std::string } } +static void completionHook(char const* prefix, linenoiseCompletions* lc) +{ + gConsole->completion(prefix, lc); +} + void console_frontend::start_console() { linenoiseInstallWindowChangeHandler(); diff --git a/src/frontend/mame/console.h b/src/frontend/mame/console.h index cdc76003336..c6f386eff69 100644 --- a/src/frontend/mame/console.h +++ b/src/frontend/mame/console.h @@ -14,6 +14,8 @@ #include "emu.h" +struct linenoiseCompletions; + class console_frontend { public: @@ -22,6 +24,7 @@ public: ~console_frontend(); void start_console(); + void completion(char const* prefix, linenoiseCompletions* lc); private: void read_console(std::string &cmdLine);