-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_gallows.h
More file actions
67 lines (55 loc) · 1.2 KB
/
text_gallows.h
File metadata and controls
67 lines (55 loc) · 1.2 KB
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
65
66
67
#ifndef TEXT_GALLOWS_H
#define TEXT_GALLOWS_H
#include <array>
#include <print>
#include <sstream>
#include <string>
#include "ansi.h"
#include "gallows.h"
class TextGallowsEntry
{
public:
TextGallowsEntry(unsigned int l, unsigned int c, std::string_view text)
: line_(l)
, column_(c)
, text_(text)
{
}
void draw() const
{
std::istringstream lines{text_};
unsigned int cur_line = line_;
std::string str;
while (std::getline(lines, str))
{
std::print("{}{}", ANSI::move_cursor(cur_line++, column_), str);
}
}
private:
unsigned int line_;
unsigned int column_;
std::string text_;
};
class TextGallows : public Gallows
{
public:
TextGallows() = default;
std::size_t stages() const override
{
return gallows_entries_.size();
};
void draw() const override
{
gallows_entries_[index_].draw();
}
void draw_state() const override
{
for (size_t i = 0; i <= index_; ++i)
{
gallows_entries_[i].draw();
}
}
private:
static const std::array<TextGallowsEntry, 11> gallows_entries_;
};
#endif // TEXT_GALLOWS_H