From ed402ee4dcb8df94c5c406e3504fa88366b6ee1d Mon Sep 17 00:00:00 2001 From: CherryJell Date: Sat, 16 May 2026 12:10:51 +0400 Subject: [PATCH 1/5] fix: ICpmmand was added in namespace cmd. --- command/src/ICommand.cppm | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/command/src/ICommand.cppm b/command/src/ICommand.cppm index bae0842..6b1223e 100644 --- a/command/src/ICommand.cppm +++ b/command/src/ICommand.cppm @@ -1,27 +1,30 @@ -module cmd:ICommand; +export module cmd:ICommand; import std; -template -struct Context +export namespace cmd { - std::vector data; -}; + template + struct Context + { + std::vector data; + }; -class ICommand -{ -protected: - ICommand() = default; + class ICommand + { + protected: + ICommand() = default; -public: - virtual ~ICommand() = default; + public: + virtual ~ICommand() = default; - ICommand(const ICommand &) = delete; - ICommand(ICommand &&) = delete; - ICommand &operator=(const ICommand &) = delete; - ICommand &operator=(ICommand &&) = delete; + ICommand(const ICommand &) = delete; + ICommand(ICommand &&) = delete; + ICommand &operator=(const ICommand &) = delete; + ICommand &operator=(ICommand &&) = delete; - virtual void Execute() = 0; - virtual void Undo() = 0; - [[nodiscard]] virtual std::string Description() const = 0; + virtual void Execute() = 0; + virtual void Undo() = 0; + [[nodiscard]] virtual std::string Description() const = 0; + }; }; \ No newline at end of file From e10fd98b7e8dbc99d363853b981046548e847dc2 Mon Sep 17 00:00:00 2001 From: CherryJell Date: Sat, 16 May 2026 13:00:02 +0400 Subject: [PATCH 2/5] fix: ecport import ICommand --- command/src/cmd.cppm | 1 + 1 file changed, 1 insertion(+) diff --git a/command/src/cmd.cppm b/command/src/cmd.cppm index 79f0f0a..78bfa90 100644 --- a/command/src/cmd.cppm +++ b/command/src/cmd.cppm @@ -2,6 +2,7 @@ export module cmd; import :ICommand; +export import :ICpmmand; export import :CommandClear; export import :CommandErase; export import :CommandHistory; From 98f6c7ec08e16abfea4e2eaeb5bfdf8f9e986341 Mon Sep 17 00:00:00 2001 From: CherryJell Date: Sat, 16 May 2026 13:03:50 +0400 Subject: [PATCH 3/5] fix: typo --- command/src/cmd.cppm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/command/src/cmd.cppm b/command/src/cmd.cppm index 78bfa90..6f1055f 100644 --- a/command/src/cmd.cppm +++ b/command/src/cmd.cppm @@ -1,8 +1,6 @@ export module cmd; -import :ICommand; - -export import :ICpmmand; +export import :ICommand; export import :CommandClear; export import :CommandErase; export import :CommandHistory; From f8bf52ddc3a8d3a2a3757370ae98a732042bc348 Mon Sep 17 00:00:00 2001 From: CherryJell Date: Sat, 16 May 2026 13:32:20 +0400 Subject: [PATCH 4/5] fix: unable to insert empty vector, unable --- command/src/CommandInsert.cppm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/src/CommandInsert.cppm b/command/src/CommandInsert.cppm index 629abdd..a770a72 100644 --- a/command/src/CommandInsert.cppm +++ b/command/src/CommandInsert.cppm @@ -17,7 +17,7 @@ export namespace cmd public: Insert(Context &ctx, std::size_t index, ContextT value) : _ctx(ctx), _index(index), _value(std::move(value)) { - if (index >= ctx.data.size()) + if ((index >= ctx.data.size()) && (_index != 0)) { throw std::out_of_range("cmd::Insert: index out of range"); } From 21f3b96a6a8f14ce8e94cbb9a4d6014ca42c07a5 Mon Sep 17 00:00:00 2001 From: CherryJell Date: Sat, 16 May 2026 13:44:36 +0400 Subject: [PATCH 5/5] feat: cmd simple usage --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 1fdea57..df335c6 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,41 @@ int main() } ``` +### `cmd::CommandHistory` example + +```cpp +import std; +import cmd; + +imt main() +{ + cmd::CommandHistory history; + cmd::Context ctx; + + try + { + history.Execute(std::make_unique>(ctx, 0, 10)); + } + catch(const std::out_of_range &e) + { + std::println("Error: {}", e.what()); + return 0; + } + + if (history.CanUndo()) + { + history.Undo(); + } + + if (history.CanRedo()) + { + history.Redo(); + } + + return 0; +} +``` + ## TODO ### Input