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
|
#include "cursor.hpp"
#include "engine/escape.hpp"
#include <cstdlib>
#include <iostream>
CursorController::CursorController(IVector2Factory vector2_factory)
: _vector2_factory(vector2_factory)
{
}
void CursorController::move_to(const IVector2 &pos)
{
fmt::print(MOVE_CURSOR_TO, fmt::arg("esc", ESC), fmt::arg("row", pos.y()),
fmt::arg("column", pos.x()));
std::cout.flush();
}
std::shared_ptr<IVector2> CursorController::where()
{
fmt::print(REQUEST_CURSOR_POSITION, fmt::arg("esc", ESC));
std::cout.flush();
IVector2Options vector2_options = {};
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
scanf("\033[%u;%uR", &vector2_options.y, &vector2_options.x);
return _vector2_factory(vector2_options);
}
void CursorController::hide()
{
fmt::print(CURSOR_INVISIBLE, fmt::arg("esc", ESC));
std::cout.flush();
}
void CursorController::show()
{
fmt::print(CURSOR_VISIBLE, fmt::arg("esc", ESC));
std::cout.flush();
}
|