1 /* Classes for abstracting ascii vs unicode output.
2 Copyright (C) 2023 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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/>. */
22 #define INCLUDE_VECTOR
24 #include "coretypes.h"
25 #include "pretty-print.h"
27 #include "text-art/selftests.h"
28 #include "text-art/ruler.h"
29 #include "text-art/theme.h"
31 using namespace text_art
;
36 theme::paint_y_arrow (canvas
&canvas
,
38 canvas::range_t y_range
,
40 style::id_t style_id
) const
44 const canvas::cell_t
head (get_cppchar (dir
== y_arrow_dir::UP
45 ? cell_kind::Y_ARROW_UP_HEAD
46 : cell_kind::Y_ARROW_DOWN_HEAD
),
48 const canvas::cell_t
tail (get_cppchar (dir
== y_arrow_dir::UP
49 ? cell_kind::Y_ARROW_UP_TAIL
50 : cell_kind::Y_ARROW_DOWN_TAIL
),
52 if (dir
== y_arrow_dir::UP
)
54 canvas_y
= y_range
.get_max ();
59 canvas_y
= y_range
.get_min ();
62 for (int len
= y_range
.get_size (); len
; len
--)
64 const canvas::cell_t cell
= (len
> 1) ? tail
: head
;
65 canvas
.paint (canvas::coord_t (canvas_x
, canvas_y
), cell
);
70 /* class ascii_theme : public theme. */
73 ascii_theme::get_line_art (directions line_dirs
) const
77 && !(line_dirs
.m_left
|| line_dirs
.m_right
))
78 return canvas::cell_t ('|');
81 && !(line_dirs
.m_up
|| line_dirs
.m_down
))
82 return canvas::cell_t ('-');
87 return canvas::cell_t ('+');
88 return canvas::cell_t (' ');
92 ascii_theme::get_cppchar (enum cell_kind kind
) const
98 case cell_kind::X_RULER_LEFT_EDGE
:
100 case cell_kind::X_RULER_MIDDLE
:
102 case cell_kind::X_RULER_INTERNAL_EDGE
:
104 case cell_kind::X_RULER_CONNECTOR_TO_LABEL_BELOW
:
105 case cell_kind::X_RULER_CONNECTOR_TO_LABEL_ABOVE
:
107 case cell_kind::X_RULER_RIGHT_EDGE
:
109 case cell_kind::X_RULER_VERTICAL_CONNECTOR
:
112 case cell_kind::TEXT_BORDER_HORIZONTAL
:
114 case cell_kind::TEXT_BORDER_VERTICAL
:
116 case cell_kind::TEXT_BORDER_TOP_LEFT
:
117 case cell_kind::TEXT_BORDER_TOP_RIGHT
:
118 case cell_kind::TEXT_BORDER_BOTTOM_LEFT
:
119 case cell_kind::TEXT_BORDER_BOTTOM_RIGHT
:
122 case cell_kind::Y_ARROW_UP_HEAD
: return '^';
123 case cell_kind::Y_ARROW_DOWN_HEAD
: return 'v';
125 case cell_kind::Y_ARROW_UP_TAIL
:
126 case cell_kind::Y_ARROW_DOWN_TAIL
:
131 /* class unicode_theme : public theme. */
134 unicode_theme::get_line_art (directions line_dirs
) const
136 return canvas::cell_t (get_box_drawing_char (line_dirs
));
140 unicode_theme::get_cppchar (enum cell_kind kind
) const
146 case cell_kind::X_RULER_LEFT_EDGE
:
147 return 0x251C; /* "├": U+251C: BOX DRAWINGS LIGHT VERTICAL AND RIGHT */
148 case cell_kind::X_RULER_MIDDLE
:
149 return 0x2500; /* "─": U+2500: BOX DRAWINGS LIGHT HORIZONTAL */
150 case cell_kind::X_RULER_INTERNAL_EDGE
:
151 return 0x253C; /* "┼": U+253C: BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */
152 case cell_kind::X_RULER_CONNECTOR_TO_LABEL_BELOW
:
153 return 0x252C; /* "┬": U+252C: BOX DRAWINGS LIGHT DOWN AND HORIZONTAL */
154 case cell_kind::X_RULER_CONNECTOR_TO_LABEL_ABOVE
:
155 return 0x2534; /* "┴": U+2534: BOX DRAWINGS LIGHT UP AND HORIZONTAL */
156 case cell_kind::X_RULER_RIGHT_EDGE
:
157 return 0x2524; /* "┤": U+2524: BOX DRAWINGS LIGHT VERTICAL AND LEFT */
158 case cell_kind::X_RULER_VERTICAL_CONNECTOR
:
159 return 0x2502; /* "│": U+2502: BOX DRAWINGS LIGHT VERTICAL */
161 case cell_kind::TEXT_BORDER_HORIZONTAL
:
162 return 0x2500; /* "─": U+2500: BOX DRAWINGS LIGHT HORIZONTAL */
163 case cell_kind::TEXT_BORDER_VERTICAL
:
164 return 0x2502; /* "│": U+2502: BOX DRAWINGS LIGHT VERTICAL */
167 case cell_kind::TEXT_BORDER_TOP_LEFT
:
168 return 0x256D; /* "╭": U+256D BOX DRAWINGS LIGHT ARC DOWN AND RIGHT. */
169 case cell_kind::TEXT_BORDER_TOP_RIGHT
:
170 return 0x256E; /* "╮": U+256E BOX DRAWINGS LIGHT ARC DOWN AND LEFT. */
171 case cell_kind::TEXT_BORDER_BOTTOM_LEFT
:
172 return 0x2570; /* "╰": U+2570 BOX DRAWINGS LIGHT ARC UP AND RIGHT. */
173 case cell_kind::TEXT_BORDER_BOTTOM_RIGHT
:
174 return 0x256F; /* "╯": U+256F BOX DRAWINGS LIGHT ARC UP AND LEFT. */
176 case cell_kind::Y_ARROW_UP_HEAD
:
178 case cell_kind::Y_ARROW_DOWN_HEAD
:
180 case cell_kind::Y_ARROW_UP_TAIL
:
181 case cell_kind::Y_ARROW_DOWN_TAIL
:
182 return 0x2502; /* "│": U+2502: BOX DRAWINGS LIGHT VERTICAL */