- ambits en la consola

- verifica que la habitacio de debug.yaml existisca
This commit is contained in:
2026-04-02 22:45:27 +02:00
parent 7287d65ca3
commit 9ffd29bea8
7 changed files with 120 additions and 9 deletions

View File

@@ -1091,6 +1091,17 @@ void CommandRegistry::load(const std::string& yaml_path) {
const std::string category = cat_node["name"].get_value<std::string>();
const bool cat_debug_only = cat_node.contains("debug_only") && cat_node["debug_only"].get_value<bool>();
// Scopes por defecto de la categoría
std::vector<std::string> cat_scopes;
if (cat_node.contains("scope")) {
const auto& scope_node = cat_node["scope"];
if (scope_node.is_sequence()) {
for (const auto& s : scope_node) { cat_scopes.push_back(s.get_value<std::string>()); }
} else {
cat_scopes.push_back(scope_node.get_value<std::string>());
}
}
if (!cat_node.contains("commands")) { continue; }
for (const auto& cmd_node : cat_node["commands"]) {
@@ -1106,6 +1117,20 @@ void CommandRegistry::load(const std::string& yaml_path) {
def.help_hidden = cmd_node.contains("help_hidden") && cmd_node["help_hidden"].get_value<bool>();
def.dynamic_completions = cmd_node.contains("dynamic_completions") && cmd_node["dynamic_completions"].get_value<bool>();
// Scopes: del comando, o hereda de la categoría, o "global" por defecto
if (cmd_node.contains("scope")) {
const auto& scope_node = cmd_node["scope"];
if (scope_node.is_sequence()) {
for (const auto& s : scope_node) { def.scopes.push_back(s.get_value<std::string>()); }
} else {
def.scopes.push_back(scope_node.get_value<std::string>());
}
} else if (!cat_scopes.empty()) {
def.scopes = cat_scopes;
} else {
def.scopes.push_back("global");
}
// Completions estáticas
if (cmd_node.contains("completions")) {
auto completions_node = cmd_node["completions"];
@@ -1208,13 +1233,40 @@ auto CommandRegistry::generateTerminalHelp() const -> std::string {
}
auto CommandRegistry::generateConsoleHelp() const -> std::string {
if (!active_scope_.empty()) {
// Con scope activo: listar solo los comandos de ese scope + global
std::string cmds;
std::string shortcuts;
for (const auto& cmd : commands_) {
if (cmd.help_hidden) { continue; }
if (!isCommandVisible(cmd)) { continue; }
std::string kw_lower = cmd.keyword;
std::ranges::transform(kw_lower, kw_lower.begin(), ::tolower);
if (!cmds.empty()) { cmds += ", "; }
cmds += kw_lower;
}
std::string result = active_scope_ + " commands:\n" + cmds + "\n";
// Atajos de teclado del editor
if (active_scope_ == "editor") {
result += "\nkeys: 9=editor 8=grid e=eraser m=map";
}
result += "\n-- more info on the terminal";
return result;
}
// Sin scope: formato original (release + debug)
std::string release_cmds;
std::string debug_cmds;
for (const auto& cmd : commands_) {
if (cmd.help_hidden) { continue; }
// Convertir keyword a minúsculas para la lista
std::string kw_lower = cmd.keyword;
std::ranges::transform(kw_lower, kw_lower.begin(), ::tolower);
@@ -1247,10 +1299,22 @@ auto CommandRegistry::getCompletions(const std::string& path) const -> std::vect
return {};
}
// Comprueba si un comando es visible en el scope activo
auto CommandRegistry::isCommandVisible(const CommandDef& cmd) const -> bool {
if (cmd.hidden) { return false; }
if (active_scope_.empty()) { return true; } // Sin filtro, todo visible
// Un comando es visible si pertenece al scope activo o al scope "global"
for (const auto& s : cmd.scopes) {
if (s == active_scope_ || s == "global") { return true; }
}
return false;
}
auto CommandRegistry::getVisibleKeywords() const -> std::vector<std::string> {
std::vector<std::string> result;
for (const auto& cmd : commands_) {
if (!cmd.hidden) {
if (isCommandVisible(cmd)) {
result.push_back(cmd.keyword);
}
}