MCPcopy Create free account
hub / github.com/DFHack/dfhack / try_autocomplete

Function try_autocomplete

library/Core.cpp:432–459  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432static bool try_autocomplete(color_ostream &con, const std::string &first, std::string &completed)
433{
434 std::vector<std::string> commands, possible;
435
436 get_commands(con, commands);
437 for (auto &command : commands)
438 if (command.substr(0, first.size()) == first)
439 possible.push_back(command);
440
441 if (possible.size() == 1)
442 {
443 completed = possible[0];
444 //fprintf(stderr, "Autocompleted %s to %s\n", , );
445 con.printerr("{} is not recognized. Did you mean {}?\n", first, completed);
446 return true;
447 }
448
449 if (possible.size() > 1 && possible.size() < 8)
450 {
451 std::string out;
452 for (size_t i = 0; i < possible.size(); i++)
453 out += " " + possible[i];
454 con.printerr("{} is not recognized. Possible completions:{}\n", first, out);
455 return true;
456 }
457
458 return false;
459}
460
461bool Core::addScriptPath(std::filesystem::path path, bool search_before)
462{

Callers 1

runCommandMethod · 0.85

Calls 2

get_commandsFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected