#include "scene.hpp" #include "engine/escape.hpp" #include #include #include Scene::Scene(IMatrixFactory matrix_factory, std::shared_ptr cursor_controller, std::shared_ptr window) noexcept : _is_shown(false), _matrix_factory(matrix_factory), _cursor_controller(std::move(cursor_controller)), _window(std::move(window)) { } void Scene::enter() noexcept { if (_is_shown) { return; } fmt::print(ENABLE_ALT_BUFFER, fmt::arg("esc", ESC)); std::cout.flush(); _is_shown = true; } void Scene::leave() noexcept { if (!_is_shown) { return; } fmt::print(DISABLE_ALT_BUFFER, fmt::arg("esc", ESC)); std::cout.flush(); _is_shown = false; } void Scene::write_status(const std::string_view &str) noexcept { const auto previous_position = _cursor_controller->where(); const auto window_size = _window->size(); _cursor_controller->move_to( Vector2({.x = 1, .y = static_cast(window_size.get_height())})); fmt::print(ERASE_ENTIRE_LINE, fmt::arg("esc", ESC)); fmt::print(fmt::runtime(str.data())); _cursor_controller->move_to(previous_position); }