#include "scene.hpp" #include "engine/escape.hpp" #include "util/color.hpp" #include #include #include #include Scene::Scene(IMatrixFactory matrix_factory, std::shared_ptr cursor_controller, std::shared_ptr window) noexcept : _is_shown(false), _matrix(matrix_factory(window->size() - Bounds({.width = 0U, .height = 1U}))), _cursor_controller(std::move(cursor_controller)), _window(std::move(window)) { _matrix->fill(" "); } 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 = 2, .y = static_cast(window_size.get_height())})); auto background_color = get_background_esc_seq(STATUSBAR_COLOR); fmt::print("{}", background_color); fmt::print(ERASE_ENTIRE_LINE, fmt::arg("esc", ESC)); fmt::print(fmt::runtime(str.data())); fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); _cursor_controller->move_to(previous_position); } const std::shared_ptr> &Scene::get_matrix() const noexcept { return _matrix; }