diff options
Diffstat (limited to 'src/engine/graphics')
-rw-r--r-- | src/engine/graphics/scene.cpp | 35 | ||||
-rw-r--r-- | src/engine/graphics/scene.hpp | 4 |
2 files changed, 15 insertions, 24 deletions
diff --git a/src/engine/graphics/scene.cpp b/src/engine/graphics/scene.cpp index 7c23c7d..8ec8ddf 100644 --- a/src/engine/graphics/scene.cpp +++ b/src/engine/graphics/scene.cpp @@ -1,13 +1,13 @@ #include "scene.hpp" +#include <cstdint> #include <fmt/core.h> +#include <iostream> #include <sys/ioctl.h> -#include <termios.h> #include <unistd.h> -#include <cstdint> -#include <iostream> #include "engine/escape.hpp" +#include "engine/io/terminal.hpp" class IComponent; @@ -19,7 +19,7 @@ Scene::Scene(const IMatrixFactory<MatrixElement> &matrix_factory) noexcept void Scene::enter() noexcept { - if (_is_shown || _original_termios != nullptr) + if (_is_shown) { return; } @@ -28,30 +28,22 @@ void Scene::enter() noexcept fmt::print(ENABLE_ALT_BUFFER, fmt::arg("esc", ESC)); std::cout.flush(); - // Create a backup of the current terminal state - _original_termios = std::make_shared<termios>(); - tcgetattr(STDIN_FILENO, _original_termios.get()); + _original_terminal_state = get_terminal_state(STDIN_FILENO); - auto new_termios = termios(*_original_termios); + auto new_terminal_state = TerminalState(_original_terminal_state); - // Set the local mode flags of the new termios structure - // - // The following flags are disabled: - // ECHO - Echoing input characters - // ICANON - Canonical mode (line by line input) - // ISIG - Generate the corresponding signals for the characters - // INTR, QUIT, SUSP and DSUSP - new_termios.c_lflag &= static_cast<std::uint32_t>(~(ECHO | ICANON | ISIG)); + new_terminal_state.set_local_mode_flag(TerminalLocalModeFlag::echo, false); + new_terminal_state.set_local_mode_flag(TerminalLocalModeFlag::icanon, false); + new_terminal_state.set_local_mode_flag(TerminalLocalModeFlag::isig, false); - // Set a new terminal state - tcsetattr(STDIN_FILENO, TCSAFLUSH, &new_termios); + set_terminal_state(STDIN_FILENO, new_terminal_state); _is_shown = true; } void Scene::leave() noexcept { - if (!_is_shown || _original_termios == nullptr) + if (!_is_shown) { return; } @@ -60,10 +52,9 @@ void Scene::leave() noexcept fmt::print(DISABLE_ALT_BUFFER, fmt::arg("esc", ESC)); std::cout.flush(); - // Restore the original terminal state - tcsetattr(STDIN_FILENO, TCSAFLUSH, _original_termios.get()); + set_terminal_state(STDIN_FILENO, _original_terminal_state); - _original_termios = nullptr; + _original_terminal_state = {}; _is_shown = false; } diff --git a/src/engine/graphics/scene.hpp b/src/engine/graphics/scene.hpp index 5b52027..da3d990 100644 --- a/src/engine/graphics/scene.hpp +++ b/src/engine/graphics/scene.hpp @@ -3,13 +3,13 @@ #include <fmt/core.h> #include <memory> #include <string_view> -#include <termios.h> #include <utility> #include <vector> #include <yacppdic/auto_wirable.hpp> #include "engine/data/bounds.hpp" #include "engine/data/vector2.hpp" +#include "engine/io/terminal.hpp" #include "interfaces/component.hpp" #include "interfaces/matrix.hpp" #include "interfaces/scene.hpp" @@ -47,7 +47,7 @@ private: std::shared_ptr<IMatrix<MatrixElement>> _matrix; bool _is_shown; - std::shared_ptr<termios> _original_termios = nullptr; + TerminalState _original_terminal_state{}; std::vector<std::pair<std::shared_ptr<IComponent>, Vector2>> _components; }; |