From 7e55efa3f7eeffbaab216a234ffd260fc2c67cae Mon Sep 17 00:00:00 2001 From: Phillip Spiess Date: Mon, 27 Nov 2017 13:10:09 -0800 Subject: [PATCH 1/2] Autocomplete built in commands (die, etc.) --- library/Core.cpp | 29 +++++++++-------------------- library/include/Core.h | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 62d605fe6..4472fe9f4 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -433,6 +433,11 @@ static bool try_autocomplete(color_ostream &con, const std::string &first, std:: { std::vector possible; + // Check for possible built in commands to autocomplete first + for (auto iter = built_in_commands.begin(); iter != built_in_commands.end(); ++iter) + if (iter->substr(0, first.size()) == first) + possible.push_back(*iter); + auto plug_mgr = Core::getInstance().getPluginManager(); for (auto it = plug_mgr->begin(); it != plug_mgr->end(); ++it) { @@ -612,28 +617,12 @@ static std::string sc_event_name (state_change_event id) { string getBuiltinCommand(std::string cmd) { std::string builtin = ""; - if (cmd == "ls" || - cmd == "help" || - cmd == "type" || - cmd == "load" || - cmd == "unload" || - cmd == "reload" || - cmd == "enable" || - cmd == "disable" || - cmd == "plug" || - cmd == "keybinding" || - cmd == "alias" || - cmd == "fpause" || - cmd == "cls" || - cmd == "die" || - cmd == "kill-lua" || - cmd == "script" || - cmd == "hide" || - cmd == "show" || - cmd == "sc-script" - ) + + // Check our list of builtin commands from the header + if (built_in_commands.count(cmd)) builtin = cmd; + // Check for some common aliases for built in commands else if (cmd == "?" || cmd == "man") builtin = "help"; diff --git a/library/include/Core.h b/library/include/Core.h index fa65645a1..ef90550b4 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -30,6 +30,7 @@ distribution. #include #include #include +#include #include #include "Console.h" #include "modules/Graphic.h" @@ -84,6 +85,29 @@ namespace DFHack SC_UNPAUSED = 8 }; + // List of built in commands + const std::set built_in_commands = { + "ls" , + "help" , + "type" , + "load" , + "unload" , + "reload" , + "enable" , + "disable" , + "plug" , + "keybinding" , + "alias" , + "fpause" , + "cls" , + "die" , + "kill-lua" , + "script" , + "hide" , + "show" , + "sc-script" + }; + class DFHACK_EXPORT StateChangeScript { public: From bbdf157a5257ec3e92df1db69d80f54f3d4e7c4f Mon Sep 17 00:00:00 2001 From: Phillip Spiess Date: Mon, 27 Nov 2017 13:45:58 -0800 Subject: [PATCH 2/2] Fixup autocomplete built ins per IRC --- library/Core.cpp | 29 ++++++++++++++++++++++++++--- library/include/Core.h | 24 ------------------------ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 4472fe9f4..47bddbab8 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -429,14 +429,37 @@ command_result Core::runCommand(color_ostream &out, const std::string &command) return CR_NOT_IMPLEMENTED; } +// List of built in commands +static const std::set built_in_commands = { + "ls" , + "help" , + "type" , + "load" , + "unload" , + "reload" , + "enable" , + "disable" , + "plug" , + "keybinding" , + "alias" , + "fpause" , + "cls" , + "die" , + "kill-lua" , + "script" , + "hide" , + "show" , + "sc-script" +}; + static bool try_autocomplete(color_ostream &con, const std::string &first, std::string &completed) { std::vector possible; // Check for possible built in commands to autocomplete first - for (auto iter = built_in_commands.begin(); iter != built_in_commands.end(); ++iter) - if (iter->substr(0, first.size()) == first) - possible.push_back(*iter); + for (auto const &command : built_in_commands) + if (command.substr(0, first.size()) == first) + possible.push_back(command); auto plug_mgr = Core::getInstance().getPluginManager(); for (auto it = plug_mgr->begin(); it != plug_mgr->end(); ++it) diff --git a/library/include/Core.h b/library/include/Core.h index ef90550b4..fa65645a1 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -30,7 +30,6 @@ distribution. #include #include #include -#include #include #include "Console.h" #include "modules/Graphic.h" @@ -85,29 +84,6 @@ namespace DFHack SC_UNPAUSED = 8 }; - // List of built in commands - const std::set built_in_commands = { - "ls" , - "help" , - "type" , - "load" , - "unload" , - "reload" , - "enable" , - "disable" , - "plug" , - "keybinding" , - "alias" , - "fpause" , - "cls" , - "die" , - "kill-lua" , - "script" , - "hide" , - "show" , - "sc-script" - }; - class DFHACK_EXPORT StateChangeScript { public: