1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include "scene.hpp"
#include "engine/escape.hpp"
#include "util/color.hpp"
#include <fmt/color.h>
#include <fmt/core.h>
#include <iostream>
#include <utility>
Scene::Scene(IMatrixFactory<std::string_view> matrix_factory,
std::shared_ptr<ICursorController> cursor_controller,
std::shared_ptr<IWindow> 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 = 2, .y = static_cast<Vector2::Value>(window_size.get_height())}));
const 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);
}
|