mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-10 17:56:21 +00:00
Add basic autocomplete (fix #95)
This commit is contained in:
@@ -417,12 +417,12 @@ void TConsole::Command_Status(const std::string&, const std::vector<std::string>
|
||||
<< "\t\tEvent handlers: " << mLuaEngine->GetRegisteredEventHandlerCount() << "\n"
|
||||
<< "\tSubsystems:\n"
|
||||
<< "\t\tGood/Starting/Bad: " << SystemsGood << "/" << SystemsStarting << "/" << SystemsBad << "\n"
|
||||
<< "\t\tShutting down/Shutdown: " << SystemsShuttingDown << "/" << SystemsShutdown << "\n"
|
||||
<< "\t\tShutting down/Shut down: " << SystemsShuttingDown << "/" << SystemsShutdown << "\n"
|
||||
<< "\t\tGood: [ " << SystemsGoodList << " ]\n"
|
||||
<< "\t\tStarting: [ " << SystemsStartingList << " ]\n"
|
||||
<< "\t\tBad: [ " << SystemsBadList << " ]\n"
|
||||
<< "\t\tShutting down: [ " << SystemsShuttingDownList << " ]\n"
|
||||
<< "\t\tShutdown: [ " << SystemsShutdownList << " ]\n"
|
||||
<< "\t\tShut down: [ " << SystemsShutdownList << " ]\n"
|
||||
<< "";
|
||||
|
||||
Application::Console().WriteRaw(Status.str());
|
||||
@@ -573,6 +573,47 @@ TConsole::TConsole() {
|
||||
beammp_error("Console died with: " + std::string(e.what()) + ". This could be a fatal error and could cause the server to terminate.");
|
||||
}
|
||||
};
|
||||
mCommandline.on_autocomplete = [this](Commandline& c, std::string stub) {
|
||||
std::vector<std::string> suggestions;
|
||||
try {
|
||||
auto cmd = TrimString(stub);
|
||||
//beammp_error("yes 1");
|
||||
//beammp_error(stub);
|
||||
if (mIsLuaConsole) { // if lua
|
||||
if (!mLuaEngine) {
|
||||
beammp_info("Lua not started yet, please try again in a second");
|
||||
} else {
|
||||
std::string prefix {};
|
||||
for (size_t i = stub.length(); i > 0; i--) {
|
||||
if (!std::isalnum(stub[i - 1]) && stub[i - 1] != '_') {
|
||||
prefix = stub.substr(0, i);
|
||||
stub = stub.substr(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto keys = mLuaEngine->GetStateGlobalKeysForState(mStateId);
|
||||
for (const auto& key : keys) {
|
||||
std::string::size_type n = key.find(stub);
|
||||
if (n == 0) {
|
||||
suggestions.push_back(prefix + key);
|
||||
//beammp_warn(cmd_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // if not lua
|
||||
for (const auto& [cmd_name, cmd_fn] : mCommandMap) {
|
||||
std::string::size_type n = cmd_name.find(stub);
|
||||
if (n == 0) {
|
||||
suggestions.push_back(cmd_name);
|
||||
//beammp_warn(cmd_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
beammp_error("Console died with: " + std::string(e.what()) + ". This could be a fatal error and could cause the server to terminate.");
|
||||
}
|
||||
return suggestions;
|
||||
};
|
||||
}
|
||||
|
||||
void TConsole::Write(const std::string& str) {
|
||||
|
||||
@@ -192,6 +192,21 @@ std::vector<TLuaResult> TLuaEngine::Debug_GetResultsToCheckForState(TLuaStateId
|
||||
return Result;
|
||||
}
|
||||
|
||||
std::vector<std::string> TLuaEngine::GetStateGlobalKeysForState(TLuaStateId StateId) {
|
||||
std::unique_lock Lock(mLuaStatesMutex);
|
||||
auto Result = mLuaStates.at(StateId)->GetStateGlobalKeys();
|
||||
return Result;
|
||||
}
|
||||
|
||||
std::vector<std::string> TLuaEngine::StateThreadData::GetStateGlobalKeys() {
|
||||
auto globals = mStateView.globals();
|
||||
std::vector<std::string> Result;
|
||||
for (const auto& [key, value] : globals) {
|
||||
Result.push_back(key.as<std::string>());
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
void TLuaEngine::WaitForAll(std::vector<std::shared_ptr<TLuaResult>>& Results, const std::optional<std::chrono::high_resolution_clock::duration>& Max) {
|
||||
for (const auto& Result : Results) {
|
||||
bool Cancelled = false;
|
||||
|
||||
Reference in New Issue
Block a user