// Copyright (c) 2020-present, Roland Munguia & Tristan Florian Bouchard. // Distributed under the MIT License (http://opensource.org/licenses/MIT) #pragma once #ifndef CSYS_HEADER_ONLY #include "csys/system.h" #endif namespace csys { /////////////////////////////////////////////////////////////////////////// // Public methods ///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // Commands-Error-Warning strings. static const std::string_view s_Set = "set"; static const std::string_view s_Get = "get"; static const std::string_view s_Help = "help"; static const std::string_view s_ErrorNoVar = "No variable provided"; static const std::string_view s_ErrorSetGetNotFound = "Command doesn't exist and/or variable is not registered"; CSYS_INLINE System::System() { // Register help command. RegisterCommand(s_Help.data(), "Display commands information", [this]() { // Custom command information display Log() << "help [command_name:String] (Optional)\n\t\t- Display command(s) information\n" << csys::endl; Log() << "set [variable_name:String] [data]\n\t\t- Assign data to given variable\n" << csys::endl; Log() << "get [variable_name:String]\n\t\t- Display data of given variable\n" << csys::endl; for (const auto &tuple : Commands()) { // Filter set and get. if (tuple.first.size() >= 5 && (tuple.first[3] == ' ' || tuple.first[4] == ' ')) continue; // Skip help command. if (tuple.first.size() == 4 && (tuple.first == "help")) continue; // Print the rest of commands Log() << tuple.second->Help(); } }); // Register pre-defined commands. m_CommandSuggestionTree.Insert(s_Set.data()); m_CommandSuggestionTree.Insert(s_Get.data()); } CSYS_INLINE System::System(const System &rhs) : m_CommandSuggestionTree(rhs.m_CommandSuggestionTree), m_VariableSuggestionTree(rhs.m_VariableSuggestionTree), m_CommandHistory(rhs.m_CommandHistory), m_ItemLog(rhs.m_ItemLog), m_RegisterCommandSuggestion(rhs.m_RegisterCommandSuggestion) { // Copy commands. for (const auto &pair : rhs.m_Commands) { m_Commands[pair.first] = std::unique_ptr(pair.second->Clone()); } // Copy scripts. for (const auto &pair: rhs.m_Scripts) { m_Scripts[pair.first] = std::make_unique