init commit
This commit is contained in:
commit
1497f114e6
47 files changed
+8358
No files matched your search
@@ -0,0 +1,54 @@
|
||||
#include "ConsoleCommand.h"
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace Bilicraft
|
||||
{
|
||||
namespace
|
||||
{
|
||||
std::string_view Trim(std::string_view text)
|
||||
{
|
||||
const auto first = text.find_first_not_of(" \t\v\f");
|
||||
if (first == std::string_view::npos) return {};
|
||||
return text.substr(first, text.find_last_not_of(" \t\v\f") - first + 1);
|
||||
}
|
||||
}
|
||||
ConsoleCommand ParseConsoleCommand(std::string_view line)
|
||||
{
|
||||
if (line.size() > 65536 || line.find_first_of("\r\n") != std::string_view::npos ||
|
||||
line.find('\0') != std::string_view::npos)
|
||||
throw std::runtime_error("<console>:1: expected a single line of at most 64 KiB");
|
||||
line = Trim(line.substr(0, line.find('#')));
|
||||
if (line.empty()) return {};
|
||||
const auto split = line.find_first_of(" \t\v\f");
|
||||
const auto verb = line.substr(0, split);
|
||||
auto rest = split == std::string_view::npos ? std::string_view{} : Trim(line.substr(split));
|
||||
if (verb == "run")
|
||||
{
|
||||
if (rest.size() >= 2 && ((rest.front() == '"' && rest.back() == '"') ||
|
||||
(rest.front() == '\'' && rest.back() == '\'')))
|
||||
rest = rest.substr(1, rest.size() - 2);
|
||||
if (rest.empty()) throw std::runtime_error("<console>:1: run requires a .act file path");
|
||||
return {ConsoleKind::Run, std::string(rest), {}};
|
||||
}
|
||||
if (verb == "help" || verb == "tasks" || verb == "quit" || verb == "exit")
|
||||
{
|
||||
if (!rest.empty()) throw std::runtime_error("<console>:1: console control command takes no arguments");
|
||||
return {verb == "help" ? ConsoleKind::Help : verb == "tasks" ? ConsoleKind::Tasks : ConsoleKind::Quit,
|
||||
{}, {}};
|
||||
}
|
||||
auto action = ParseInteractiveCommand(line);
|
||||
return {action ? ConsoleKind::Action : ConsoleKind::Empty, {}, std::move(action)};
|
||||
}
|
||||
std::string ConsoleHelp()
|
||||
{
|
||||
return "Console: run <path.act> | tasks | help | quit (or exit)\n"
|
||||
"Game commands: goto, rclick, lclick, grclick, glclick, sw, swb, drop, sendcmd, sendmsg\n"
|
||||
"rclick/lclick: add entry [t|b|s|n|w|e] for item frames; omit face to require a unique frame.\n"
|
||||
"A game command waits until the running action finishes or reaches wait.\n"
|
||||
"Only one interactive game command can be pending. wait/import are not allowed here.\n"
|
||||
"run validates and queues a file immediately; newest ready action runs first.\n"
|
||||
"Native terminal: fixed input bar, Up/Down history, Left/Right/Home/End editing.\n"
|
||||
"Ctrl+C/quit cancels; EOF drains queued tasks, then disconnects.\n";
|
||||
}
|
||||
} // namespace Bilicraft
|
||||
Reference in new issue
Block a user