aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-23 19:41:31 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:57 +0200
commit486ca3846b46dc229e5807968578809766ec1991 (patch)
tree65a4b7a746d6305666af06f8a1975c76244085a7 /src/commands
parentb8e86ce397dc07320c02f6a5f592c7c6a4421c86 (diff)
feat: implement generations & multithreading
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/toggle_pause.cpp22
-rw-r--r--src/commands/toggle_pause.hpp20
2 files changed, 42 insertions, 0 deletions
diff --git a/src/commands/toggle_pause.cpp b/src/commands/toggle_pause.cpp
new file mode 100644
index 0000000..8a3f44c
--- /dev/null
+++ b/src/commands/toggle_pause.cpp
@@ -0,0 +1,22 @@
+#include "toggle_pause.hpp"
+
+#include <fmt/core.h>
+#include <utility>
+
+TogglePauseCommand::TogglePauseCommand(
+ std::shared_ptr<IGenerationTracker> generation_tracker,
+ std::shared_ptr<IStatusLine> statusline) noexcept
+ : _generation_tracker(std::move(generation_tracker)),
+ _statusline(std::move(statusline))
+{
+}
+
+void TogglePauseCommand::execute() noexcept
+{
+ auto onoff = !_generation_tracker->get_is_paused();
+
+ _generation_tracker->set_is_paused(onoff);
+
+ _statusline->set_status(StatusLineSection::B,
+ fmt::format("Paused: {}", onoff ? "yes" : "no"));
+}
diff --git a/src/commands/toggle_pause.hpp b/src/commands/toggle_pause.hpp
new file mode 100644
index 0000000..4e05323
--- /dev/null
+++ b/src/commands/toggle_pause.hpp
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "interfaces/command.hpp"
+#include "interfaces/generation_tracker.hpp"
+#include "interfaces/statusline.hpp"
+
+#include <memory>
+
+class TogglePauseCommand : public ICommand
+{
+public:
+ explicit TogglePauseCommand(std::shared_ptr<IGenerationTracker> generation_tracker,
+ std::shared_ptr<IStatusLine> statusline) noexcept;
+
+ void execute() noexcept override;
+
+private:
+ std::shared_ptr<IGenerationTracker> _generation_tracker;
+ std::shared_ptr<IStatusLine> _statusline;
+};