completion to console class (nw)

This commit is contained in:
Miodrag Milanovic 2016-10-12 18:35:15 +02:00
parent ad7584603a
commit 06d0afbef9
2 changed files with 17 additions and 11 deletions

View File

@ -16,7 +16,7 @@
#include <atomic> #include <atomic>
#include <thread> #include <thread>
static console_frontend *gConsole = nullptr;
//------------------------------------------------- //-------------------------------------------------
// console_frontend - constructor // console_frontend - constructor
//------------------------------------------------- //-------------------------------------------------
@ -31,6 +31,7 @@ console_frontend::console_frontend(emu_options &options, osd_interface &osd)
using namespace std::placeholders; 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("quit", std::bind(&console_frontend::cmd_quit, this, _1)));
m_commands.insert(std::make_pair("exit", 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[] = { void console_frontend::completion(char const* prefix, linenoiseCompletions* lc)
"quit", "exit", NULL {
}; for (auto cmd : m_commands)
{
void completionHook(char const* prefix, linenoiseCompletions* lc) { if (strncmp(prefix, cmd.first.c_str(), strlen(prefix)) == 0)
size_t i; {
linenoiseAddCompletion(lc, cmd.first.c_str());
for (i = 0; commandList[i] != NULL; ++i) {
if (strncmp(prefix, commandList[i], strlen(prefix)) == 0) {
linenoiseAddCompletion(lc, commandList[i]);
} }
} }
} }
@ -131,6 +129,11 @@ void console_frontend::split_command(std::vector<std::string>& arg, std::string
} }
} }
static void completionHook(char const* prefix, linenoiseCompletions* lc)
{
gConsole->completion(prefix, lc);
}
void console_frontend::start_console() void console_frontend::start_console()
{ {
linenoiseInstallWindowChangeHandler(); linenoiseInstallWindowChangeHandler();

View File

@ -14,6 +14,8 @@
#include "emu.h" #include "emu.h"
struct linenoiseCompletions;
class console_frontend class console_frontend
{ {
public: public:
@ -22,6 +24,7 @@ public:
~console_frontend(); ~console_frontend();
void start_console(); void start_console();
void completion(char const* prefix, linenoiseCompletions* lc);
private: private:
void read_console(std::string &cmdLine); void read_console(std::string &cmdLine);