| 487 | } |
| 488 | |
| 489 | command_result Plugin::invoke(color_ostream &out, const std::string & command, std::vector <std::string> & parameters) |
| 490 | { |
| 491 | command_result cr = CR_NOT_IMPLEMENTED; |
| 492 | access->lock_add(); |
| 493 | if (state == PS_LOADED) { |
| 494 | if (auto cmdIt = std::ranges::find_if(commands, [&](const PluginCommand &cmd) { return cmd.name == command; }); |
| 495 | commands.end() != cmdIt) |
| 496 | { |
| 497 | // running interactive things from some other source than the console would break it |
| 498 | if (!out.is_console() && cmdIt->interactive) |
| 499 | cr = CR_NEEDS_CONSOLE; |
| 500 | else if (cmdIt->guard) { |
| 501 | CoreSuspender suspend; |
| 502 | if (!cmdIt->guard(Core::getInstance().getTopViewscreen())) { |
| 503 | out.printerr("Could not invoke {}: unsuitable UI state.\n", command); |
| 504 | cr = CR_WRONG_USAGE; |
| 505 | } |
| 506 | else { |
| 507 | cr = cmdIt->function(out, parameters); |
| 508 | } |
| 509 | } |
| 510 | else if (cmdIt->unlocked) { |
| 511 | cr = cmdIt->function(out, parameters); |
| 512 | } |
| 513 | else { |
| 514 | CoreSuspender suspend; |
| 515 | cr = cmdIt->function(out, parameters); |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | access->lock_sub(); |
| 520 | return cr; |
| 521 | } |
| 522 | |
| 523 | bool Plugin::can_invoke_hotkey(const std::string & command, df::viewscreen *top ) |
| 524 | { |
no test coverage detected