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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/* Classes for abstracting ascii vs unicode output.
Copyright (C) 2023 Free Software Foundation, Inc.
Contributed by David Malcolm <dmalcolm@redhat.com>.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef GCC_TEXT_ART_THEME_H
#define GCC_TEXT_ART_THEME_H
#include "text-art/canvas.h"
#include "text-art/box-drawing.h"
namespace text_art {
class theme
{
public:
enum class cell_kind
{
/* A left-hand edge of a range e.g. "├". */
X_RULER_LEFT_EDGE,
/* Within a range e.g. "─". */
X_RULER_MIDDLE,
/* A border between two neighboring ranges e.g. "┼". */
X_RULER_INTERNAL_EDGE,
/* The connector with the text label within a range e.g. "┬". */
X_RULER_CONNECTOR_TO_LABEL_BELOW,
/* As above, but when the text label is above the ruler. */
X_RULER_CONNECTOR_TO_LABEL_ABOVE,
/* The vertical connection to a text label. */
X_RULER_VERTICAL_CONNECTOR,
/* A right-hand edge of a range e.g. "┤". */
X_RULER_RIGHT_EDGE,
TEXT_BORDER_HORIZONTAL,
TEXT_BORDER_VERTICAL,
TEXT_BORDER_TOP_LEFT,
TEXT_BORDER_TOP_RIGHT,
TEXT_BORDER_BOTTOM_LEFT,
TEXT_BORDER_BOTTOM_RIGHT,
Y_ARROW_UP_HEAD,
Y_ARROW_UP_TAIL,
Y_ARROW_DOWN_HEAD,
Y_ARROW_DOWN_TAIL,
};
virtual ~theme () = default;
virtual bool unicode_p () const = 0;
virtual bool emojis_p () const = 0;
virtual canvas::cell_t
get_line_art (directions line_dirs) const = 0;
canvas::cell_t get_cell (enum cell_kind kind, unsigned style_idx) const
{
return canvas::cell_t (get_cppchar (kind), false, style_idx);
}
virtual cppchar_t get_cppchar (enum cell_kind kind) const = 0;
enum class y_arrow_dir { UP, DOWN };
void paint_y_arrow (canvas &canvas,
int x,
canvas::range_t y_range,
y_arrow_dir dir,
style::id_t style_id) const;
};
class ascii_theme : public theme
{
public:
bool unicode_p () const final override { return false; }
bool emojis_p () const final override { return false; }
canvas::cell_t
get_line_art (directions line_dirs) const final override;
cppchar_t get_cppchar (enum cell_kind kind) const final override;
};
class unicode_theme : public theme
{
public:
bool unicode_p () const final override { return true; }
bool emojis_p () const override { return false; }
canvas::cell_t
get_line_art (directions line_dirs) const final override;
cppchar_t get_cppchar (enum cell_kind kind) const final override;
};
class emoji_theme : public unicode_theme
{
public:
bool emojis_p () const final override { return true; }
};
} // namespace text_art
#endif /* GCC_TEXT_ART_THEME_H */
|