#pragma once #include #include #include #include #include namespace dragonx { namespace ui { struct ConsoleCompletionResult { std::vector matches; std::string commonPrefix; }; struct ConsoleRpcCall { bool valid = false; std::string method; nlohmann::json params = nlohmann::json::array(); std::string error; // set (with valid=false) when an argument fails to parse }; enum class ConsoleResultLineRole { Result, Error, JsonKey, JsonString, JsonNumber, JsonBrace }; struct ConsoleResultLine { std::string text; ConsoleResultLineRole role = ConsoleResultLineRole::Result; }; const std::vector& ConsoleRpcCommandNames(); void AppendConsoleHistory(std::vector& history, const std::string& command, std::size_t maxEntries = 100); int NavigateConsoleHistoryIndex(int currentIndex, std::size_t historySize, bool up); std::string ConsoleHistoryEntry(const std::vector& history, int historyIndex); ConsoleCompletionResult CompleteConsoleCommand(const std::string& input); std::vector FormatConsoleCompletionLines(const std::vector& matches, std::size_t maxLineLength = 60); // A tokenized console argument. `quoted` is true when the token came from a "..."/'...' literal, // so BuildConsoleRpcCall must send it verbatim as a JSON string (never coerce it to a number/bool). struct ConsoleArg { std::string text; bool quoted = false; }; std::vector ParseConsoleCommandArgsTagged(const std::string& command); std::vector ParseConsoleCommandArgs(const std::string& command); ConsoleRpcCall BuildConsoleRpcCall(const std::string& command); // Splits an RPC result into classified lines (std::getline semantics: a trailing '\n' adds no // empty line, an empty result yields none). `maxLines` > 0 keeps only the LAST maxLines lines, // found by a backward newline scan so a huge result is never fully split/copied. The JSON // classification still keys off the first char of the whole result. 0 = no cap. std::vector FormatConsoleRpcResultLines(std::string_view result, bool isError, std::size_t maxLines = 0); // For a block of pretty-printed JSON lines, return a per-line fold span: for a line that // opens a collapsible block (its last non-space char is '{' or '[') the value is the offset // to its matching closing-bracket line at the same indentation; 0 for every other line and // for empty/one-line blocks not worth folding (span < 2). Pure; used to drive console // JSON folding. std::vector ComputeConsoleFoldSpans(const std::vector& lines); // Same as ComputeConsoleFoldSpans, over formatted result lines directly (no text copies). std::vector ComputeConsoleResultFoldSpans(const std::vector& lines); } // namespace ui } // namespace dragonx