19#define WIN32_LEAN_AND_MEAN
27#if !defined(FTXUI_UNLIKELY)
28#if defined(COMPILER_GCC) || defined(__clang__)
29#define FTXUI_UNLIKELY(x) __builtin_expect(!!(x), 0)
31#define FTXUI_UNLIKELY(x) (x)
35#if !defined(FTXUI_LIKELY)
36#if defined(COMPILER_GCC) || defined(__clang__)
37#define FTXUI_LIKELY(x) __builtin_expect(!!(x), 1)
39#define FTXUI_LIKELY(x) (x)
49 static bool done =
false;
72 std::stringstream&
ss,
77 ss <<
"\x1B]8;;" <<
screen->Hyperlink(
next.hyperlink) <<
"\x1B\\";
85 ss << (
next.bold ?
"\x1B[1m" :
"");
86 ss << (
next.dim ?
"\x1B[2m" :
"");
91 next.underlined_double !=
prev.underlined_double)) {
92 ss << (
next.underlined ?
"\x1B[4m"
93 :
next.underlined_double ?
"\x1B[21m"
99 ss << (
next.blink ?
"\x1B[5m"
105 ss << (
next.inverted ?
"\x1B[7m"
111 ss << (
next.strikethrough ?
"\x1B[9m"
116 next.background_color !=
prev.background_color)) {
117 ss <<
"\x1B[" +
next.foreground_color.Print(
false) +
"m";
118 ss <<
"\x1B[" +
next.background_color.Print(
true) +
"m";
123 std::uint8_t left : 2;
124 std::uint8_t top : 2;
125 std::uint8_t right : 2;
126 std::uint8_t down : 2;
127 std::uint8_t round : 1;
130 bool operator<(
const TileEncoding&
other)
const {
131 if (left <
other.left) {
return true; }
132 if (left >
other.left) {
return false; }
133 if (top <
other.top) {
return true; }
134 if (top >
other.top) {
return false; }
135 if (right <
other.right) {
return true; }
136 if (right >
other.right) {
return false; }
137 if (down <
other.down) {
return true; }
138 if (down >
other.down) {
return false; }
139 if (round <
other.round) {
return true; }
140 if (round >
other.round) {
return false; }
148 {
"─", {1, 0, 1, 0, 0}},
149 {
"━", {2, 0, 2, 0, 0}},
150 {
"╍", {2, 0, 2, 0, 0}},
152 {
"│", {0, 1, 0, 1, 0}},
153 {
"┃", {0, 2, 0, 2, 0}},
154 {
"╏", {0, 2, 0, 2, 0}},
156 {
"┌", {0, 0, 1, 1, 0}},
157 {
"┍", {0, 0, 2, 1, 0}},
158 {
"┎", {0, 0, 1, 2, 0}},
159 {
"┏", {0, 0, 2, 2, 0}},
161 {
"┐", {1, 0, 0, 1, 0}},
162 {
"┑", {2, 0, 0, 1, 0}},
163 {
"┒", {1, 0, 0, 2, 0}},
164 {
"┓", {2, 0, 0, 2, 0}},
166 {
"└", {0, 1, 1, 0, 0}},
167 {
"┕", {0, 1, 2, 0, 0}},
168 {
"┖", {0, 2, 1, 0, 0}},
169 {
"┗", {0, 2, 2, 0, 0}},
171 {
"┘", {1, 1, 0, 0, 0}},
172 {
"┙", {2, 1, 0, 0, 0}},
173 {
"┚", {1, 2, 0, 0, 0}},
174 {
"┛", {2, 2, 0, 0, 0}},
176 {
"├", {0, 1, 1, 1, 0}},
177 {
"┝", {0, 1, 2, 1, 0}},
178 {
"┞", {0, 2, 1, 1, 0}},
179 {
"┟", {0, 1, 1, 2, 0}},
180 {
"┠", {0, 2, 1, 2, 0}},
181 {
"┡", {0, 2, 2, 1, 0}},
182 {
"┢", {0, 1, 2, 2, 0}},
183 {
"┣", {0, 2, 2, 2, 0}},
185 {
"┤", {1, 1, 0, 1, 0}},
186 {
"┥", {2, 1, 0, 1, 0}},
187 {
"┦", {1, 2, 0, 1, 0}},
188 {
"┧", {1, 1, 0, 2, 0}},
189 {
"┨", {1, 2, 0, 2, 0}},
190 {
"┩", {2, 2, 0, 1, 0}},
191 {
"┪", {2, 1, 0, 2, 0}},
192 {
"┫", {2, 2, 0, 2, 0}},
194 {
"┬", {1, 0, 1, 1, 0}},
195 {
"┭", {2, 0, 1, 1, 0}},
196 {
"┮", {1, 0, 2, 1, 0}},
197 {
"┯", {2, 0, 2, 1, 0}},
198 {
"┰", {1, 0, 1, 2, 0}},
199 {
"┱", {2, 0, 1, 2, 0}},
200 {
"┲", {1, 0, 2, 2, 0}},
201 {
"┳", {2, 0, 2, 2, 0}},
203 {
"┴", {1, 1, 1, 0, 0}},
204 {
"┵", {2, 1, 1, 0, 0}},
205 {
"┶", {1, 1, 2, 0, 0}},
206 {
"┷", {2, 1, 2, 0, 0}},
207 {
"┸", {1, 2, 1, 0, 0}},
208 {
"┹", {2, 2, 1, 0, 0}},
209 {
"┺", {1, 2, 2, 0, 0}},
210 {
"┻", {2, 2, 2, 0, 0}},
212 {
"┼", {1, 1, 1, 1, 0}},
213 {
"┽", {2, 1, 1, 1, 0}},
214 {
"┾", {1, 1, 2, 1, 0}},
215 {
"┿", {2, 1, 2, 1, 0}},
216 {
"╀", {1, 2, 1, 1, 0}},
217 {
"╁", {1, 1, 1, 2, 0}},
218 {
"╂", {1, 2, 1, 2, 0}},
219 {
"╃", {2, 2, 1, 1, 0}},
220 {
"╄", {1, 2, 2, 1, 0}},
221 {
"╅", {2, 1, 1, 2, 0}},
222 {
"╆", {1, 1, 2, 2, 0}},
223 {
"╇", {2, 2, 2, 1, 0}},
224 {
"╈", {2, 1, 2, 2, 0}},
225 {
"╉", {2, 2, 1, 2, 0}},
226 {
"╊", {1, 2, 2, 2, 0}},
227 {
"╋", {2, 2, 2, 2, 0}},
229 {
"═", {3, 0, 3, 0, 0}},
230 {
"║", {0, 3, 0, 3, 0}},
232 {
"╒", {0, 0, 3, 1, 0}},
233 {
"╓", {0, 0, 1, 3, 0}},
234 {
"╔", {0, 0, 3, 3, 0}},
236 {
"╕", {3, 0, 0, 1, 0}},
237 {
"╖", {1, 0, 0, 3, 0}},
238 {
"╗", {3, 0, 0, 3, 0}},
240 {
"╘", {0, 1, 3, 0, 0}},
241 {
"╙", {0, 3, 1, 0, 0}},
242 {
"╚", {0, 3, 3, 0, 0}},
244 {
"╛", {3, 1, 0, 0, 0}},
245 {
"╜", {1, 3, 0, 0, 0}},
246 {
"╝", {3, 3, 0, 0, 0}},
248 {
"╞", {0, 1, 3, 1, 0}},
249 {
"╟", {0, 3, 1, 3, 0}},
250 {
"╠", {0, 3, 3, 3, 0}},
252 {
"╡", {3, 1, 0, 1, 0}},
253 {
"╢", {1, 3, 0, 3, 0}},
254 {
"╣", {3, 3, 0, 3, 0}},
256 {
"╤", {3, 0, 3, 1, 0}},
257 {
"╥", {1, 0, 1, 3, 0}},
258 {
"╦", {3, 0, 3, 3, 0}},
260 {
"╧", {3, 1, 3, 0, 0}},
261 {
"╨", {1, 3, 1, 0, 0}},
262 {
"╩", {3, 3, 3, 0, 0}},
264 {
"╪", {3, 1, 3, 1, 0}},
265 {
"╫", {1, 3, 1, 3, 0}},
266 {
"╬", {3, 3, 3, 3, 0}},
268 {
"╭", {0, 0, 1, 1, 1}},
269 {
"╮", {1, 0, 0, 1, 1}},
270 {
"╯", {1, 1, 0, 0, 1}},
271 {
"╰", {0, 1, 1, 0, 1}},
273 {
"╴", {1, 0, 0, 0, 0}},
274 {
"╵", {0, 1, 0, 0, 0}},
275 {
"╶", {0, 0, 1, 0, 0}},
276 {
"╷", {0, 0, 0, 1, 0}},
278 {
"╸", {2, 0, 0, 0, 0}},
279 {
"╹", {0, 2, 0, 0, 0}},
280 {
"╺", {0, 0, 2, 0, 0}},
281 {
"╻", {0, 0, 0, 2, 0}},
283 {
"╼", {1, 0, 2, 0, 0}},
284 {
"╽", {0, 1, 0, 2, 0}},
285 {
"╾", {2, 0, 1, 0, 0}},
286 {
"╿", {0, 2, 0, 1, 0}},
290template <
class A,
class B>
291std::map<B, A>
InvertMap(
const std::map<A, B> input) {
293 for (
const auto&
it : input) {
361 return pixel.automerge &&
pixel.character.size() == 3;
410 std::stringstream
ss;
415 for (
int y = 0; y <
dimy_; ++y) {
429 if (
pixel.character.empty()) {
447 std::cout <<
ToString() <<
'\0' << std::flush;
470 std::stringstream
ss;
474 for (
int y = 1; y <
dimy_; ++y) {
480 for (
int y = 1; y <
dimy_; ++y) {
502 for (
int y = 0; y <
dimy_; ++y) {
503 for (
int x = 0; x <
dimx_; ++x) {
528 for (std::size_t i = 0; i <
hyperlinks_.size(); ++i) {
533 if (
hyperlinks_.size() == std::numeric_limits<std::uint8_t>::max()) {
A rectangular grid of Pixel.
void Clear()
Clear all the pixel from the screen.
std::vector< std::vector< Pixel > > pixels_
A rectangular grid of Pixel.
std::function< void(Pixel &)> SelectionStyle
const SelectionStyle & GetSelectionStyle() const
Return the current selection style.
const std::string & Hyperlink(uint8_t id) const
std::string ToString() const
static Screen Create(Dimensions dimension)
Create a screen with the given dimension.
uint8_t RegisterHyperlink(const std::string &link)
Screen(int dimx, int dimy)
std::string ResetPosition(bool clear=false) const
Return a string to be printed in order to reset the cursor position to the beginning of the screen.
void Clear()
Clear all the pixel from the screen.
SelectionStyle selection_style_
void SetSelectionStyle(SelectionStyle decorator)
Set the current selection style.
std::vector< std::string > hyperlinks_
Dimensions Size()
Get the terminal size.
std::shared_ptr< T > Make(Args &&... args)
int string_width(const std::string &)
#define FTXUI_UNLIKELY(x)
A Unicode character and its associated style.