1 | /* Classes for abstracting ascii vs unicode output. |
2 | Copyright (C) 2023-2024 Free Software Foundation, Inc. |
3 | Contributed by David Malcolm <dmalcolm@redhat.com>. |
4 | |
5 | This file is part of GCC. |
6 | |
7 | GCC is free software; you can redistribute it and/or modify it |
8 | under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 3, or (at your option) |
10 | any later version. |
11 | |
12 | GCC is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ |
20 | |
21 | #ifndef GCC_TEXT_ART_THEME_H |
22 | #define GCC_TEXT_ART_THEME_H |
23 | |
24 | #include "text-art/canvas.h" |
25 | #include "text-art/box-drawing.h" |
26 | |
27 | namespace text_art { |
28 | |
29 | class theme |
30 | { |
31 | public: |
32 | enum class cell_kind |
33 | { |
34 | /* A left-hand edge of a range e.g. "├". */ |
35 | X_RULER_LEFT_EDGE, |
36 | |
37 | /* Within a range e.g. "─". */ |
38 | X_RULER_MIDDLE, |
39 | |
40 | /* A border between two neighboring ranges e.g. "┼". */ |
41 | X_RULER_INTERNAL_EDGE, |
42 | |
43 | /* The connector with the text label within a range e.g. "┬". */ |
44 | X_RULER_CONNECTOR_TO_LABEL_BELOW, |
45 | |
46 | /* As above, but when the text label is above the ruler. */ |
47 | X_RULER_CONNECTOR_TO_LABEL_ABOVE, |
48 | |
49 | /* The vertical connection to a text label. */ |
50 | X_RULER_VERTICAL_CONNECTOR, |
51 | |
52 | /* A right-hand edge of a range e.g. "┤". */ |
53 | X_RULER_RIGHT_EDGE, |
54 | |
55 | TEXT_BORDER_HORIZONTAL, |
56 | TEXT_BORDER_VERTICAL, |
57 | TEXT_BORDER_TOP_LEFT, |
58 | TEXT_BORDER_TOP_RIGHT, |
59 | TEXT_BORDER_BOTTOM_LEFT, |
60 | TEXT_BORDER_BOTTOM_RIGHT, |
61 | |
62 | Y_ARROW_UP_HEAD, |
63 | Y_ARROW_UP_TAIL, |
64 | Y_ARROW_DOWN_HEAD, |
65 | Y_ARROW_DOWN_TAIL, |
66 | }; |
67 | |
68 | virtual ~theme () = default; |
69 | |
70 | virtual bool unicode_p () const = 0; |
71 | virtual bool emojis_p () const = 0; |
72 | |
73 | virtual canvas::cell_t |
74 | get_line_art (directions line_dirs) const = 0; |
75 | |
76 | canvas::cell_t get_cell (enum cell_kind kind, unsigned style_idx) const |
77 | { |
78 | return canvas::cell_t (get_cppchar (kind), false, style_idx); |
79 | } |
80 | |
81 | virtual cppchar_t get_cppchar (enum cell_kind kind) const = 0; |
82 | |
83 | enum class y_arrow_dir { UP, DOWN }; |
84 | void paint_y_arrow (canvas &canvas, |
85 | int x, |
86 | canvas::range_t y_range, |
87 | y_arrow_dir dir, |
88 | style::id_t style_id) const; |
89 | }; |
90 | |
91 | class ascii_theme : public theme |
92 | { |
93 | public: |
94 | bool unicode_p () const final override { return false; } |
95 | bool emojis_p () const final override { return false; } |
96 | |
97 | canvas::cell_t |
98 | get_line_art (directions line_dirs) const final override; |
99 | |
100 | cppchar_t get_cppchar (enum cell_kind kind) const final override; |
101 | }; |
102 | |
103 | class unicode_theme : public theme |
104 | { |
105 | public: |
106 | bool unicode_p () const final override { return true; } |
107 | bool emojis_p () const override { return false; } |
108 | |
109 | canvas::cell_t |
110 | get_line_art (directions line_dirs) const final override; |
111 | |
112 | cppchar_t get_cppchar (enum cell_kind kind) const final override; |
113 | }; |
114 | |
115 | class emoji_theme : public unicode_theme |
116 | { |
117 | public: |
118 | bool emojis_p () const final override { return true; } |
119 | }; |
120 | |
121 | } // namespace text_art |
122 | |
123 | #endif /* GCC_TEXT_ART_THEME_H */ |
124 | |