#include "component_renderer.hpp" #include "engine/escape.hpp" #include "util/color.hpp" #include #include #include ComponentRenderer::ComponentRenderer( std::shared_ptr cursor_controller) noexcept : _cursor_controller(std::move(cursor_controller)) { } void ComponentRenderer::render( const std::shared_ptr &component, const Vector2 &position) noexcept { const auto previous_pos = _cursor_controller->where(); _cursor_controller->hide(); _cursor_controller->move_to(position); const auto component_matrix = component->get(); const auto foreground_color = component->get_foreground_color(); const auto background_color = component->get_background_color(); fmt::print( "{}{}", get_background_esc_seq(background_color), get_foreground_esc_seq(foreground_color)); for (const auto &row : *component_matrix) { for (const auto &col : row) { std::cout.put(col); } const auto current_pos = _cursor_controller->where(); _cursor_controller->move_to( Vector2({.x = previous_pos.get_x(), .y = current_pos.get_y() - 1})); } fmt::print(RESET_ALL_MODES, fmt::arg("esc", ESC)); std::cout.flush(); _cursor_controller->move_to(previous_pos); _cursor_controller->show(); }