CNDP  22.08.0
vt100_out.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2019-2022 Intel Corporation.
3  */
4 
5 #ifndef __VT100_OUT_H_
6 #define __VT100_OUT_H_
7 
13 // IWYU pragma no_include <bits/termios-struct.h>
14 
15 #include <stdarg.h> // for va_end, va_list, va_start
16 #include <stdint.h> // for int16_t, uint8_t
17 #include <stdio.h> // for snprintf, NULL
18 #include <string.h> // for strlen
19 #include <termios.h>
20 #include <unistd.h> // for write
21 
22 #include <cne_atomic.h> // for atomic_exchange, atomic_int_least32_t, atomic...
23 #include <cne_common.h>
24 #include <cne_system.h>
25 #include <cne_tty.h> // for tty_printf, tty_write
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #define VT_DEFAULT_NAME "default"
32 
34 typedef uint8_t vt_rgb_t;
35 
38 typedef enum {
39  VT_BLACK = 0,
40  VT_RED = 1,
41  VT_GREEN = 2,
42  VT_YELLOW = 3,
43  VT_BLUE = 4,
44  VT_MAGENTA = 5,
45  VT_CYAN = 6,
46  VT_WHITE = 7,
47  VT_RGB = 8,
48  VT_DEFAULT_FG = 9,
49  VT_DEFAULT_BG = 9,
50  VT_RGB_FG = 38,
51  VT_RGB_BG = 48,
52  VT_DEFAULT_RGB_FG = 39,
53  VT_DEFAULT_RGB_BG = 49,
54  VT_NO_CHANGE = 98,
55  VT_UNKNOWN_COLOR = 99
56 } vt_color_e;
57 
58 /* Order of the following color enums is important and must be the
59  * same order as the rgb color name strings and codes below.
60  */
61 // clang-format off
62 enum {
63  ColorDefault = 0,
64  ColorBlack,
65  ColorMaroon,
66  ColorGreen,
67  ColorOlive,
68  ColorNavy,
69  ColorPurple,
70  ColorTeal,
71  ColorSilver,
72  ColorGray,
73  ColorRed,
74  ColorLime,
75  ColorYellow,
76  ColorBlue,
77  ColorFuchsia,
78  ColorAqua,
79  ColorWhite,
80  Color16,
81  Color17,
82  Color18,
83  Color19,
84  Color20,
85  Color21,
86  Color22,
87  Color23,
88  Color24,
89  Color25,
90  Color26,
91  Color27,
92  Color28,
93  Color29,
94  Color30,
95  Color31,
96  Color32,
97  Color33,
98  Color34,
99  Color35,
100  Color36,
101  Color37,
102  Color38,
103  Color39,
104  Color40,
105  Color41,
106  Color42,
107  Color43,
108  Color44,
109  Color45,
110  Color46,
111  Color47,
112  Color48,
113  Color49,
114  Color50,
115  Color51,
116  Color52,
117  Color53,
118  Color54,
119  Color55,
120  Color56,
121  Color57,
122  Color58,
123  Color59,
124  Color60,
125  Color61,
126  Color62,
127  Color63,
128  Color64,
129  Color65,
130  Color66,
131  Color67,
132  Color68,
133  Color69,
134  Color70,
135  Color71,
136  Color72,
137  Color73,
138  Color74,
139  Color75,
140  Color76,
141  Color77,
142  Color78,
143  Color79,
144  Color80,
145  Color81,
146  Color82,
147  Color83,
148  Color84,
149  Color85,
150  Color86,
151  Color87,
152  Color88,
153  Color89,
154  Color90,
155  Color91,
156  Color92,
157  Color93,
158  Color94,
159  Color95,
160  Color96,
161  Color97,
162  Color98,
163  Color99,
164  Color100,
165  Color101,
166  Color102,
167  Color103,
168  Color104,
169  Color105,
170  Color106,
171  Color107,
172  Color108,
173  Color109,
174  Color110,
175  Color111,
176  Color112,
177  Color113,
178  Color114,
179  Color115,
180  Color116,
181  Color117,
182  Color118,
183  Color119,
184  Color120,
185  Color121,
186  Color122,
187  Color123,
188  Color124,
189  Color125,
190  Color126,
191  Color127,
192  Color128,
193  Color129,
194  Color130,
195  Color131,
196  Color132,
197  Color133,
198  Color134,
199  Color135,
200  Color136,
201  Color137,
202  Color138,
203  Color139,
204  Color140,
205  Color141,
206  Color142,
207  Color143,
208  Color144,
209  Color145,
210  Color146,
211  Color147,
212  Color148,
213  Color149,
214  Color150,
215  Color151,
216  Color152,
217  Color153,
218  Color154,
219  Color155,
220  Color156,
221  Color157,
222  Color158,
223  Color159,
224  Color160,
225  Color161,
226  Color162,
227  Color163,
228  Color164,
229  Color165,
230  Color166,
231  Color167,
232  Color168,
233  Color169,
234  Color170,
235  Color171,
236  Color172,
237  Color173,
238  Color174,
239  Color175,
240  Color176,
241  Color177,
242  Color178,
243  Color179,
244  Color180,
245  Color181,
246  Color182,
247  Color183,
248  Color184,
249  Color185,
250  Color186,
251  Color187,
252  Color188,
253  Color189,
254  Color190,
255  Color191,
256  Color192,
257  Color193,
258  Color194,
259  Color195,
260  Color196,
261  Color197,
262  Color198,
263  Color199,
264  Color200,
265  Color201,
266  Color202,
267  Color203,
268  Color204,
269  Color205,
270  Color206,
271  Color207,
272  Color208,
273  Color209,
274  Color210,
275  Color211,
276  Color212,
277  Color213,
278  Color214,
279  Color215,
280  Color216,
281  Color217,
282  Color218,
283  Color219,
284  Color220,
285  Color221,
286  Color222,
287  Color223,
288  Color224,
289  Color225,
290  Color226,
291  Color227,
292  Color228,
293  Color229,
294  Color230,
295  Color231,
296  Color232,
297  Color233,
298  Color234,
299  Color235,
300  Color236,
301  Color237,
302  Color238,
303  Color239,
304  Color240,
305  Color241,
306  Color242,
307  Color243,
308  Color244,
309  Color245,
310  Color246,
311  Color247,
312  Color248,
313  Color249,
314  Color250,
315  Color251,
316  Color252,
317  Color253,
318  Color254,
319  Color255,
320  ColorAliceBlue,
321  ColorAntiqueWhite,
322  ColorAquaMarine,
323  ColorAzure,
324  ColorBeige,
325  ColorBisque,
326  ColorBlanchedAlmond,
327  ColorBlueViolet,
328  ColorBrown,
329  ColorBurlyWood,
330  ColorCadetBlue,
331  ColorChartreuse,
332  ColorChocolate,
333  ColorCoral,
334  ColorCornflowerBlue,
335  ColorCornsilk,
336  ColorCrimson,
337  ColorDarkBlue,
338  ColorDarkCyan,
339  ColorDarkGoldenrod,
340  ColorDarkGray,
341  ColorDarkGreen,
342  ColorDarkKhaki,
343  ColorDarkMagenta,
344  ColorDarkOliveGreen,
345  ColorDarkOrange,
346  ColorDarkOrchid,
347  ColorDarkRed,
348  ColorDarkSalmon,
349  ColorDarkSeaGreen,
350  ColorDarkSlateBlue,
351  ColorDarkSlateGray,
352  ColorDarkTurquoise,
353  ColorDarkViolet,
354  ColorDeepPink,
355  ColorDeepSkyBlue,
356  ColorDimGray,
357  ColorDodgerBlue,
358  ColorFireBrick,
359  ColorFloralWhite,
360  ColorForestGreen,
361  ColorGainsboro,
362  ColorGhostWhite,
363  ColorGold,
364  ColorGoldenrod,
365  ColorGreenYellow,
366  ColorHoneydew,
367  ColorHotPink,
368  ColorIndianRed,
369  ColorIndigo,
370  ColorIvory,
371  ColorKhaki,
372  ColorLavender,
373  ColorLavenderBlush,
374  ColorLawnGreen,
375  ColorLemonChiffon,
376  ColorLightBlue,
377  ColorLightCoral,
378  ColorLightCyan,
379  ColorLightGoldenrodYellow,
380  ColorLightGray,
381  ColorLightGreen,
382  ColorLightPink,
383  ColorLightSalmon,
384  ColorLightSeaGreen,
385  ColorLightSkyBlue,
386  ColorLightSlateGray,
387  ColorLightSteelBlue,
388  ColorLightYellow,
389  ColorLimeGreen,
390  ColorLinen,
391  ColorMediumAquamarine,
392  ColorMediumBlue,
393  ColorMediumOrchid,
394  ColorMediumPurple,
395  ColorMediumSeaGreen,
396  ColorMediumSlateBlue,
397  ColorMediumSpringGreen,
398  ColorMediumTurquoise,
399  ColorMediumVioletRed,
400  ColorMidnightBlue,
401  ColorMintCream,
402  ColorMistyRose,
403  ColorMoccasin,
404  ColorNavajoWhite,
405  ColorOldLace,
406  ColorOliveDrab,
407  ColorOrange,
408  ColorOrangeRed,
409  ColorOrchid,
410  ColorPaleGoldenrod,
411  ColorPaleGreen,
412  ColorPaleTurquoise,
413  ColorPaleVioletRed,
414  ColorPapayaWhip,
415  ColorPeachPuff,
416  ColorPeru,
417  ColorPink,
418  ColorPlum,
419  ColorPowderBlue,
420  ColorRebeccaPurple,
421  ColorRosyBrown,
422  ColorRoyalBlue,
423  ColorSaddleBrown,
424  ColorSalmon,
425  ColorSandyBrown,
426  ColorSeaGreen,
427  ColorSeashell,
428  ColorSienna,
429  ColorSkyblue,
430  ColorSlateBlue,
431  ColorSlateGray,
432  ColorSnow,
433  ColorSpringGreen,
434  ColorSteelBlue,
435  ColorTan,
436  ColorThistle,
437  ColorTomato,
438  ColorTurquoise,
439  ColorViolet,
440  ColorWheat,
441  ColorWhiteSmoke,
442  ColorYellowGreen,
443 };
444 // clang-format on
445 
446 #define COLOR_DEFAULT 0xc0dedead
448 /* ColorValues constants to their RGB values. */
449 typedef struct {
450  int color_id;
451  unsigned rgb_color;
452 } vt_rgb_code_t;
453 
454 /* Copyright 2015 The TCell Authors
455  *
456  * Licensed under the Apache License, Version 2.0 (the "License");
457  * you may not use file except in compliance with the License.
458  * You may obtain a copy of the license at
459  *
460  * http://www.apache.org/licenses/LICENSE-2.0
461  *
462  * Unless required by applicable law or agreed to in writing, software
463  * distributed under the License is distributed on an "AS IS" BASIS,
464  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
465  * See the License for the specific language governing permissions and
466  * limitations under the License.
467  *
468  * Source located at: https://github.com/gdamore/tcell file color.go
469  *
470  * Only the color codes (RGB_COLOR_CODES) and IDs were used from this source.
471  */
472 
473 // clang-format off
474 #define RGB_COLOR_CODES { \
475  { ColorDefault , COLOR_DEFAULT }, \
476  { ColorBlack , 0x000000 }, \
477  { ColorMaroon , 0x800000 }, \
478  { ColorGreen , 0x008000 }, \
479  { ColorOlive , 0x808000 }, \
480  { ColorNavy , 0x000080 }, \
481  { ColorPurple , 0x800080 }, \
482  { ColorTeal , 0x008080 }, \
483  { ColorSilver , 0xC0C0C0 }, \
484  { ColorGray , 0x808080 }, \
485  { ColorRed , 0xFF0000 }, \
486  { ColorLime , 0x00FF00 }, \
487  { ColorYellow , 0xFFFF00 }, \
488  { ColorBlue , 0x0000FF }, \
489  { ColorFuchsia , 0xFF00FF }, \
490  { ColorAqua , 0x00FFFF }, \
491  { ColorWhite , 0xFFFFFF }, \
492  { Color16 , 0x000000 }, /* black */ \
493  { Color17 , 0x00005F }, \
494  { Color18 , 0x000087 }, \
495  { Color19 , 0x0000AF }, \
496  { Color20 , 0x0000D7 }, \
497  { Color21 , 0x0000FF }, /* blue */ \
498  { Color22 , 0x005F00 }, \
499  { Color23 , 0x005F5F }, \
500  { Color24 , 0x005F87 }, \
501  { Color25 , 0x005FAF }, \
502  { Color26 , 0x005FD7 }, \
503  { Color27 , 0x005FFF }, \
504  { Color28 , 0x008700 }, \
505  { Color29 , 0x00875F }, \
506  { Color30 , 0x008787 }, \
507  { Color31 , 0x0087Af }, \
508  { Color32 , 0x0087D7 }, \
509  { Color33 , 0x0087FF }, \
510  { Color34 , 0x00AF00 }, \
511  { Color35 , 0x00AF5F }, \
512  { Color36 , 0x00AF87 }, \
513  { Color37 , 0x00AFAF }, \
514  { Color38 , 0x00AFD7 }, \
515  { Color39 , 0x00AFFF }, \
516  { Color40 , 0x00D700 }, \
517  { Color41 , 0x00D75F }, \
518  { Color42 , 0x00D787 }, \
519  { Color43 , 0x00D7AF }, \
520  { Color44 , 0x00D7D7 }, \
521  { Color45 , 0x00D7FF }, \
522  { Color46 , 0x00FF00 }, /* lime */ \
523  { Color47 , 0x00FF5F }, \
524  { Color48 , 0x00FF87 }, \
525  { Color49 , 0x00FFAF }, \
526  { Color50 , 0x00FFd7 }, \
527  { Color51 , 0x00FFFF }, /* aqua */ \
528  { Color52 , 0x5F0000 }, \
529  { Color53 , 0x5F005F }, \
530  { Color54 , 0x5F0087 }, \
531  { Color55 , 0x5F00AF }, \
532  { Color56 , 0x5F00D7 }, \
533  { Color57 , 0x5F00FF }, \
534  { Color58 , 0x5F5F00 }, \
535  { Color59 , 0x5F5F5F }, \
536  { Color60 , 0x5F5F87 }, \
537  { Color61 , 0x5F5FAF }, \
538  { Color62 , 0x5F5FD7 }, \
539  { Color63 , 0x5F5FFF }, \
540  { Color64 , 0x5F8700 }, \
541  { Color65 , 0x5F875F }, \
542  { Color66 , 0x5F8787 }, \
543  { Color67 , 0x5F87AF }, \
544  { Color68 , 0x5F87D7 }, \
545  { Color69 , 0x5F87FF }, \
546  { Color70 , 0x5FAF00 }, \
547  { Color71 , 0x5FAF5F }, \
548  { Color72 , 0x5FAF87 }, \
549  { Color73 , 0x5FAFAF }, \
550  { Color74 , 0x5FAFD7 }, \
551  { Color75 , 0x5FAFFF }, \
552  { Color76 , 0x5FD700 }, \
553  { Color77 , 0x5FD75F }, \
554  { Color78 , 0x5FD787 }, \
555  { Color79 , 0x5FD7AF }, \
556  { Color80 , 0x5FD7D7 }, \
557  { Color81 , 0x5FD7FF }, \
558  { Color82 , 0x5FFF00 }, \
559  { Color83 , 0x5FFF5F }, \
560  { Color84 , 0x5FFF87 }, \
561  { Color85 , 0x5FFFAF }, \
562  { Color86 , 0x5FFFD7 }, \
563  { Color87 , 0x5FFFFF }, \
564  { Color88 , 0x870000 }, \
565  { Color89 , 0x87005F }, \
566  { Color90 , 0x870087 }, \
567  { Color91 , 0x8700AF }, \
568  { Color92 , 0x8700D7 }, \
569  { Color93 , 0x8700FF }, \
570  { Color94 , 0x875F00 }, \
571  { Color95 , 0x875F5F }, \
572  { Color96 , 0x875F87 }, \
573  { Color97 , 0x875FAF }, \
574  { Color98 , 0x875FD7 }, \
575  { Color99 , 0x875FFF }, \
576  { Color100 , 0x878700 }, \
577  { Color101 , 0x87875F }, \
578  { Color102 , 0x878787 }, \
579  { Color103 , 0x8787AF }, \
580  { Color104 , 0x8787D7 }, \
581  { Color105 , 0x8787FF }, \
582  { Color106 , 0x87AF00 }, \
583  { Color107 , 0x87AF5F }, \
584  { Color108 , 0x87AF87 }, \
585  { Color109 , 0x87AFAF }, \
586  { Color110 , 0x87AFD7 }, \
587  { Color111 , 0x87AFFF }, \
588  { Color112 , 0x87D700 }, \
589  { Color113 , 0x87D75F }, \
590  { Color114 , 0x87D787 }, \
591  { Color115 , 0x87D7AF }, \
592  { Color116 , 0x87D7D7 }, \
593  { Color117 , 0x87D7FF }, \
594  { Color118 , 0x87FF00 }, \
595  { Color119 , 0x87FF5F }, \
596  { Color120 , 0x87FF87 }, \
597  { Color121 , 0x87FFAF }, \
598  { Color122 , 0x87FFD7 }, \
599  { Color123 , 0x87FFFF }, \
600  { Color124 , 0xAF0000 }, \
601  { Color125 , 0xAF005F }, \
602  { Color126 , 0xAF0087 }, \
603  { Color127 , 0xAF00AF }, \
604  { Color128 , 0xAF00D7 }, \
605  { Color129 , 0xAF00FF }, \
606  { Color130 , 0xAF5F00 }, \
607  { Color131 , 0xAF5F5F }, \
608  { Color132 , 0xAF5F87 }, \
609  { Color133 , 0xAF5FAF }, \
610  { Color134 , 0xAF5FD7 }, \
611  { Color135 , 0xAF5FFF }, \
612  { Color136 , 0xAF8700 }, \
613  { Color137 , 0xAF875F }, \
614  { Color138 , 0xAF8787 }, \
615  { Color139 , 0xAF87AF }, \
616  { Color140 , 0xAF87D7 }, \
617  { Color141 , 0xAF87FF }, \
618  { Color142 , 0xAFAF00 }, \
619  { Color143 , 0xAFAF5F }, \
620  { Color144 , 0xAFAF87 }, \
621  { Color145 , 0xAFAFAF }, \
622  { Color146 , 0xAFAFD7 }, \
623  { Color147 , 0xAFAFFF }, \
624  { Color148 , 0xAFD700 }, \
625  { Color149 , 0xAFD75F }, \
626  { Color150 , 0xAFD787 }, \
627  { Color151 , 0xAFD7AF }, \
628  { Color152 , 0xAFD7D7 }, \
629  { Color153 , 0xAFD7FF }, \
630  { Color154 , 0xAFFF00 }, \
631  { Color155 , 0xAFFF5F }, \
632  { Color156 , 0xAFFF87 }, \
633  { Color157 , 0xAFFFAF }, \
634  { Color158 , 0xAFFFD7 }, \
635  { Color159 , 0xAFFFFF }, \
636  { Color160 , 0xD70000 }, \
637  { Color161 , 0xD7005F }, \
638  { Color162 , 0xD70087 }, \
639  { Color163 , 0xD700AF }, \
640  { Color164 , 0xD700D7 }, \
641  { Color165 , 0xD700FF }, \
642  { Color166 , 0xD75F00 }, \
643  { Color167 , 0xD75F5F }, \
644  { Color168 , 0xD75F87 }, \
645  { Color169 , 0xD75FAF }, \
646  { Color170 , 0xD75FD7 }, \
647  { Color171 , 0xD75FFF }, \
648  { Color172 , 0xD78700 }, \
649  { Color173 , 0xD7875F }, \
650  { Color174 , 0xD78787 }, \
651  { Color175 , 0xD787AF }, \
652  { Color176 , 0xD787D7 }, \
653  { Color177 , 0xD787FF }, \
654  { Color178 , 0xD7AF00 }, \
655  { Color179 , 0xD7AF5F }, \
656  { Color180 , 0xD7AF87 }, \
657  { Color181 , 0xD7AFAF }, \
658  { Color182 , 0xD7AFD7 }, \
659  { Color183 , 0xD7AFFF }, \
660  { Color184 , 0xD7D700 }, \
661  { Color185 , 0xD7D75F }, \
662  { Color186 , 0xD7D787 }, \
663  { Color187 , 0xD7D7AF }, \
664  { Color188 , 0xD7D7D7 }, \
665  { Color189 , 0xD7D7FF }, \
666  { Color190 , 0xD7FF00 }, \
667  { Color191 , 0xD7FF5F }, \
668  { Color192 , 0xD7FF87 }, \
669  { Color193 , 0xD7FFAF }, \
670  { Color194 , 0xD7FFD7 }, \
671  { Color195 , 0xD7FFFF }, \
672  { Color196 , 0xFF0000 }, /* red */ \
673  { Color197 , 0xFF005F }, \
674  { Color198 , 0xFF0087 }, \
675  { Color199 , 0xFF00AF }, \
676  { Color200 , 0xFF00D7 }, \
677  { Color201 , 0xFF00FF }, /* fuchsia */ \
678  { Color202 , 0xFF5F00 }, \
679  { Color203 , 0xFF5F5F }, \
680  { Color204 , 0xFF5F87 }, \
681  { Color205 , 0xFF5FAF }, \
682  { Color206 , 0xFF5FD7 }, \
683  { Color207 , 0xFF5FFF }, \
684  { Color208 , 0xFF8700 }, \
685  { Color209 , 0xFF875F }, \
686  { Color210 , 0xFF8787 }, \
687  { Color211 , 0xFF87AF }, \
688  { Color212 , 0xFF87D7 }, \
689  { Color213 , 0xFF87FF }, \
690  { Color214 , 0xFFAF00 }, \
691  { Color215 , 0xFFAF5F }, \
692  { Color216 , 0xFFAF87 }, \
693  { Color217 , 0xFFAFAF }, \
694  { Color218 , 0xFFAFD7 }, \
695  { Color219 , 0xFFAFFF }, \
696  { Color220 , 0xFFD700 }, \
697  { Color221 , 0xFFD75F }, \
698  { Color222 , 0xFFD787 }, \
699  { Color223 , 0xFFD7AF }, \
700  { Color224 , 0xFFD7D7 }, \
701  { Color225 , 0xFFD7FF }, \
702  { Color226 , 0xFFFF00 }, /* yellow */ \
703  { Color227 , 0xFFFF5F }, \
704  { Color228 , 0xFFFF87 }, \
705  { Color229 , 0xFFFFAF }, \
706  { Color230 , 0xFFFFD7 }, \
707  { Color231 , 0xFFFFFF }, /* white */ \
708  { Color232 , 0x080808 }, \
709  { Color233 , 0x121212 }, \
710  { Color234 , 0x1C1C1C }, \
711  { Color235 , 0x262626 }, \
712  { Color236 , 0x303030 }, \
713  { Color237 , 0x3A3A3A }, \
714  { Color238 , 0x444444 }, \
715  { Color239 , 0x4E4E4E }, \
716  { Color240 , 0x585858 }, \
717  { Color241 , 0x626262 }, \
718  { Color242 , 0x6C6C6C }, \
719  { Color243 , 0x767676 }, \
720  { Color244 , 0x808080 }, /* grey */ \
721  { Color245 , 0x8A8A8A }, \
722  { Color246 , 0x949494 }, \
723  { Color247 , 0x9E9E9E }, \
724  { Color248 , 0xA8A8A8 }, \
725  { Color249 , 0xB2B2B2 }, \
726  { Color250 , 0xBCBCBC }, \
727  { Color251 , 0xC6C6C6 }, \
728  { Color252 , 0xD0D0D0 }, \
729  { Color253 , 0xDADADA }, \
730  { Color254 , 0xE4E4E4 }, \
731  { Color255 , 0xEEEEEE }, \
732  { ColorAliceBlue , 0xF0F8FF }, \
733  { ColorAntiqueWhite , 0xFAEBD7 }, \
734  { ColorAquaMarine , 0x7FFFD4 }, \
735  { ColorAzure , 0xF0FFFF }, \
736  { ColorBeige , 0xF5F5DC }, \
737  { ColorBisque , 0xFFE4C4 }, \
738  { ColorBlanchedAlmond , 0xFFEBCD }, \
739  { ColorBlueViolet , 0x8A2BE2 }, \
740  { ColorBrown , 0xA52A2A }, \
741  { ColorBurlyWood , 0xDEB887 }, \
742  { ColorCadetBlue , 0x5F9EA0 }, \
743  { ColorChartreuse , 0x7FFF00 }, \
744  { ColorChocolate , 0xD2691E }, \
745  { ColorCoral , 0xFF7F50 }, \
746  { ColorCornflowerBlue , 0x6495ED }, \
747  { ColorCornsilk , 0xFFF8DC }, \
748  { ColorCrimson , 0xDC143C }, \
749  { ColorDarkBlue , 0x00008B }, \
750  { ColorDarkCyan , 0x008B8B }, \
751  { ColorDarkGoldenrod , 0xB8860B }, \
752  { ColorDarkGray , 0xA9A9A9 }, \
753  { ColorDarkGreen , 0x006400 }, \
754  { ColorDarkKhaki , 0xBDB76B }, \
755  { ColorDarkMagenta , 0x8B008B }, \
756  { ColorDarkOliveGreen , 0x556B2F }, \
757  { ColorDarkOrange , 0xFF8C00 }, \
758  { ColorDarkOrchid , 0x9932CC }, \
759  { ColorDarkRed , 0x8B0000 }, \
760  { ColorDarkSalmon , 0xE9967A }, \
761  { ColorDarkSeaGreen , 0x8FBC8F }, \
762  { ColorDarkSlateBlue , 0x483D8B }, \
763  { ColorDarkSlateGray , 0x2F4F4F }, \
764  { ColorDarkTurquoise , 0x00CED1 }, \
765  { ColorDarkViolet , 0x9400D3 }, \
766  { ColorDeepPink , 0xFF1493 }, \
767  { ColorDeepSkyBlue , 0x00BFFF }, \
768  { ColorDimGray , 0x696969 }, \
769  { ColorDodgerBlue , 0x1E90FF }, \
770  { ColorFireBrick , 0xB22222 }, \
771  { ColorFloralWhite , 0xFFFAF0 }, \
772  { ColorForestGreen , 0x228B22 }, \
773  { ColorGainsboro , 0xDCDCDC }, \
774  { ColorGhostWhite , 0xF8F8FF }, \
775  { ColorGold , 0xFFD700 }, \
776  { ColorGoldenrod , 0xDAA520 }, \
777  { ColorGreenYellow , 0xADFF2F }, \
778  { ColorHoneydew , 0xF0FFF0 }, \
779  { ColorHotPink , 0xFF69B4 }, \
780  { ColorIndianRed , 0xCD5C5C }, \
781  { ColorIndigo , 0x4B0082 }, \
782  { ColorIvory , 0xFFFFF0 }, \
783  { ColorKhaki , 0xF0E68C }, \
784  { ColorLavender , 0xE6E6FA }, \
785  { ColorLavenderBlush , 0xFFF0F5 }, \
786  { ColorLawnGreen , 0x7CFC00 }, \
787  { ColorLemonChiffon , 0xFFFACD }, \
788  { ColorLightBlue , 0xADD8E6 }, \
789  { ColorLightCoral , 0xF08080 }, \
790  { ColorLightCyan , 0xE0FFFF }, \
791  { ColorLightGoldenrodYellow , 0xFAFAD2 }, \
792  { ColorLightGray , 0xD3D3D3 }, \
793  { ColorLightGreen , 0x90EE90 }, \
794  { ColorLightPink , 0xFFB6C1 }, \
795  { ColorLightSalmon , 0xFFA07A }, \
796  { ColorLightSeaGreen , 0x20B2AA }, \
797  { ColorLightSkyBlue , 0x87CEFA }, \
798  { ColorLightSlateGray , 0x778899 }, \
799  { ColorLightSteelBlue , 0xB0C4DE }, \
800  { ColorLightYellow , 0xFFFFE0 }, \
801  { ColorLimeGreen , 0x32CD32 }, \
802  { ColorLinen , 0xFAF0E6 }, \
803  { ColorMediumAquamarine , 0x66CDAA }, \
804  { ColorMediumBlue , 0x0000CD }, \
805  { ColorMediumOrchid , 0xBA55D3 }, \
806  { ColorMediumPurple , 0x9370DB }, \
807  { ColorMediumSeaGreen , 0x3CB371 }, \
808  { ColorMediumSlateBlue , 0x7B68EE }, \
809  { ColorMediumSpringGreen , 0x00FA9A }, \
810  { ColorMediumTurquoise , 0x48D1CC }, \
811  { ColorMediumVioletRed , 0xC71585 }, \
812  { ColorMidnightBlue , 0x191970 }, \
813  { ColorMintCream , 0xF5FFFA }, \
814  { ColorMistyRose , 0xFFE4E1 }, \
815  { ColorMoccasin , 0xFFE4B5 }, \
816  { ColorNavajoWhite , 0xFFDEAD }, \
817  { ColorOldLace , 0xFDF5E6 }, \
818  { ColorOliveDrab , 0x6B8E23 }, \
819  { ColorOrange , 0xFFA500 }, \
820  { ColorOrangeRed , 0xFF4500 }, \
821  { ColorOrchid , 0xDA70D6 }, \
822  { ColorPaleGoldenrod , 0xEEE8AA }, \
823  { ColorPaleGreen , 0x98FB98 }, \
824  { ColorPaleTurquoise , 0xAFEEEE }, \
825  { ColorPaleVioletRed , 0xDB7093 }, \
826  { ColorPapayaWhip , 0xFFEFD5 }, \
827  { ColorPeachPuff , 0xFFDAB9 }, \
828  { ColorPeru , 0xCD853F }, \
829  { ColorPink , 0xFFC0CB }, \
830  { ColorPlum , 0xDDA0DD }, \
831  { ColorPowderBlue , 0xB0E0E6 }, \
832  { ColorRebeccaPurple , 0x663399 }, \
833  { ColorRosyBrown , 0xBC8F8F }, \
834  { ColorRoyalBlue , 0x4169E1 }, \
835  { ColorSaddleBrown , 0x8B4513 }, \
836  { ColorSalmon , 0xFA8072 }, \
837  { ColorSandyBrown , 0xF4A460 }, \
838  { ColorSeaGreen , 0x2E8B57 }, \
839  { ColorSeashell , 0xFFF5EE }, \
840  { ColorSienna , 0xA0522D }, \
841  { ColorSkyblue , 0x87CEEB }, \
842  { ColorSlateBlue , 0x6A5ACD }, \
843  { ColorSlateGray , 0x708090 }, \
844  { ColorSnow , 0xFFFAFA }, \
845  { ColorSpringGreen , 0x00FF7F }, \
846  { ColorSteelBlue , 0x4682B4 }, \
847  { ColorTan , 0xD2B48C }, \
848  { ColorThistle , 0xD8BFD8 }, \
849  { ColorTomato , 0xFF6347 }, \
850  { ColorTurquoise , 0x40E0D0 }, \
851  { ColorViolet , 0xEE82EE }, \
852  { ColorWheat , 0xF5DEB3 }, \
853  { ColorWhiteSmoke , 0xF5F5F5 }, \
854  { ColorYellowGreen , 0x9ACD32 }, \
855  { -1, -1 } \
856 }
857 // clang-format on
858 
859 typedef struct {
860  const char *name;
861  int color_id;
862 } vt_rgb_name_t;
863 
864 // clang-format off
865 #define RGB_COLOR_NAMES { \
866  { "default" , ColorDefault }, \
867  { "black" , ColorBlack }, \
868  { "maroon" , ColorMaroon }, \
869  { "green" , ColorGreen }, \
870  { "olive" , ColorOlive }, \
871  { "navy" , ColorNavy }, \
872  { "purple" , ColorPurple }, \
873  { "teal" , ColorTeal }, \
874  { "silver" , ColorSilver }, \
875  { "gray" , ColorGray }, \
876  { "red" , ColorRed }, \
877  { "lime" , ColorLime }, \
878  { "yellow" , ColorYellow }, \
879  { "blue" , ColorBlue }, \
880  { "fuchsia" , ColorFuchsia }, \
881  { "aqua" , ColorAqua }, \
882  { "white" , ColorWhite }, \
883  { "aliceblue" , ColorAliceBlue }, \
884  { "antiquewhite" , ColorAntiqueWhite }, \
885  { "aquamarine" , ColorAquaMarine }, \
886  { "azure" , ColorAzure }, \
887  { "beige" , ColorBeige }, \
888  { "bisque" , ColorBisque }, \
889  { "blanchedalmond" , ColorBlanchedAlmond }, \
890  { "blueviolet" , ColorBlueViolet }, \
891  { "brown" , ColorBrown }, \
892  { "burlywood" , ColorBurlyWood }, \
893  { "cadetblue" , ColorCadetBlue }, \
894  { "chartreuse" , ColorChartreuse }, \
895  { "chocolate" , ColorChocolate }, \
896  { "coral" , ColorCoral }, \
897  { "cornflowerblue" , ColorCornflowerBlue }, \
898  { "cornsilk" , ColorCornsilk }, \
899  { "crimson" , ColorCrimson }, \
900  { "darkblue" , ColorDarkBlue }, \
901  { "darkcyan" , ColorDarkCyan }, \
902  { "darkgoldenrod" , ColorDarkGoldenrod }, \
903  { "darkgray" , ColorDarkGray }, \
904  { "darkgreen" , ColorDarkGreen }, \
905  { "darkkhaki" , ColorDarkKhaki }, \
906  { "darkmagenta" , ColorDarkMagenta }, \
907  { "darkolivegreen" , ColorDarkOliveGreen }, \
908  { "darkorange" , ColorDarkOrange }, \
909  { "darkorchid" , ColorDarkOrchid }, \
910  { "darkred" , ColorDarkRed }, \
911  { "darksalmon" , ColorDarkSalmon }, \
912  { "darkseagreen" , ColorDarkSeaGreen }, \
913  { "darkslateblue" , ColorDarkSlateBlue }, \
914  { "darkslategray" , ColorDarkSlateGray }, \
915  { "darkturquoise" , ColorDarkTurquoise }, \
916  { "darkviolet" , ColorDarkViolet }, \
917  { "deeppink" , ColorDeepPink }, \
918  { "deepskyblue" , ColorDeepSkyBlue }, \
919  { "dimgray" , ColorDimGray }, \
920  { "dodgerblue" , ColorDodgerBlue }, \
921  { "firebrick" , ColorFireBrick }, \
922  { "floralwhite" , ColorFloralWhite }, \
923  { "forestgreen" , ColorForestGreen }, \
924  { "gainsboro" , ColorGainsboro }, \
925  { "ghostwhite" , ColorGhostWhite }, \
926  { "gold" , ColorGold }, \
927  { "goldenrod" , ColorGoldenrod }, \
928  { "greenyellow" , ColorGreenYellow }, \
929  { "honeydew" , ColorHoneydew }, \
930  { "hotpink" , ColorHotPink }, \
931  { "indianred" , ColorIndianRed }, \
932  { "indigo" , ColorIndigo }, \
933  { "ivory" , ColorIvory }, \
934  { "khaki" , ColorKhaki }, \
935  { "lavender" , ColorLavender }, \
936  { "lavenderblush" , ColorLavenderBlush }, \
937  { "lawngreen" , ColorLawnGreen }, \
938  { "lemonchiffon" , ColorLemonChiffon }, \
939  { "lightblue" , ColorLightBlue }, \
940  { "lightcoral" , ColorLightCoral }, \
941  { "lightcyan" , ColorLightCyan }, \
942  { "lightgoldenrodyellow" , ColorLightGoldenrodYellow }, \
943  { "lightgray" , ColorLightGray }, \
944  { "lightgreen" , ColorLightGreen }, \
945  { "lightpink" , ColorLightPink }, \
946  { "lightsalmon" , ColorLightSalmon }, \
947  { "lightseagreen" , ColorLightSeaGreen }, \
948  { "lightskyblue" , ColorLightSkyBlue }, \
949  { "lightslategray" , ColorLightSlateGray }, \
950  { "lightsteelblue" , ColorLightSteelBlue }, \
951  { "lightyellow" , ColorLightYellow }, \
952  { "limegreen" , ColorLimeGreen }, \
953  { "linen" , ColorLinen }, \
954  { "mediumaquamarine" , ColorMediumAquamarine }, \
955  { "mediumblue" , ColorMediumBlue }, \
956  { "mediumorchid" , ColorMediumOrchid }, \
957  { "mediumpurple" , ColorMediumPurple }, \
958  { "mediumseagreen" , ColorMediumSeaGreen }, \
959  { "mediumslateblue" , ColorMediumSlateBlue }, \
960  { "mediumspringgreen" , ColorMediumSpringGreen }, \
961  { "mediumturquoise" , ColorMediumTurquoise }, \
962  { "mediumvioletred" , ColorMediumVioletRed }, \
963  { "midnightblue" , ColorMidnightBlue }, \
964  { "mintcream" , ColorMintCream }, \
965  { "mistyrose" , ColorMistyRose }, \
966  { "moccasin" , ColorMoccasin }, \
967  { "navajowhite" , ColorNavajoWhite }, \
968  { "oldlace" , ColorOldLace }, \
969  { "olivedrab" , ColorOliveDrab }, \
970  { "orange" , ColorOrange }, \
971  { "orangered" , ColorOrangeRed }, \
972  { "orchid" , ColorOrchid }, \
973  { "palegoldenrod" , ColorPaleGoldenrod }, \
974  { "palegreen" , ColorPaleGreen }, \
975  { "paleturquoise" , ColorPaleTurquoise }, \
976  { "palevioletred" , ColorPaleVioletRed }, \
977  { "papayawhip" , ColorPapayaWhip }, \
978  { "peachpuff" , ColorPeachPuff }, \
979  { "peru" , ColorPeru }, \
980  { "pink" , ColorPink }, \
981  { "plum" , ColorPlum }, \
982  { "powderblue" , ColorPowderBlue }, \
983  { "rebeccapurple" , ColorRebeccaPurple }, \
984  { "rosybrown" , ColorRosyBrown }, \
985  { "royalblue" , ColorRoyalBlue }, \
986  { "saddlebrown" , ColorSaddleBrown }, \
987  { "salmon" , ColorSalmon }, \
988  { "sandybrown" , ColorSandyBrown }, \
989  { "seagreen" , ColorSeaGreen }, \
990  { "seashell" , ColorSeashell }, \
991  { "sienna" , ColorSienna }, \
992  { "skyblue" , ColorSkyblue }, \
993  { "slateblue" , ColorSlateBlue }, \
994  { "slategray" , ColorSlateGray }, \
995  { "snow" , ColorSnow }, \
996  { "springgreen" , ColorSpringGreen }, \
997  { "steelblue" , ColorSteelBlue }, \
998  { "tan" , ColorTan }, \
999  { "thistle" , ColorThistle }, \
1000  { "tomato" , ColorTomato }, \
1001  { "turquoise" , ColorTurquoise }, \
1002  { "violet" , ColorViolet }, \
1003  { "wheat" , ColorWheat }, \
1004  { "whitesmoke" , ColorWhiteSmoke }, \
1005  { "yellowgreen" , ColorYellowGreen }, \
1006  { "grey" , ColorGray }, \
1007  { "dimgrey" , ColorDimGray }, \
1008  { "darkgrey" , ColorDarkGray }, \
1009  { "darkslategrey" , ColorDarkSlateGray }, \
1010  { "lightgrey" , ColorLightGray }, \
1011  { "lightslategrey" , ColorLightSlateGray }, \
1012  { "slategrey" , ColorSlateGray }, \
1013  { "magenta" , ColorFuchsia}, \
1014  { "cyan" , ColorAqua}, \
1015  { NULL, -1 } \
1016 }
1017 // clang-format on
1018 
1020 typedef enum {
1021  VT_OFF = 0,
1022  VT_BOLD = 1,
1023  VT_FAINT = 2,
1024  VT_ITALIC = 3,
1025  VT_UNDERSCORE = 4,
1026  VT_SLOW_BLINK = 5,
1027  VT_FAST_BLINK = 6,
1028  VT_REVERSE = 7,
1029  VT_CONCEALED = 8,
1030  VT_CROSSOUT = 9,
1031  VT_DEFAULT_FONT = 10,
1032  VT_UNDERLINE_OFF = 24,
1033  VT_BLINK_OFF = 25,
1034  VT_INVERSE_OFF = 27,
1035  VT_REVEAL = 28,
1036  VT_NOT_CROSSED_OUT = 29,
1037  /* 30-39 and 40-49 Foreground and Background colors */
1038  VT_FRAMED = 51,
1039  VT_ENCIRCLED = 52,
1040  VT_OVERLINED = 53,
1041  VT_NOT_FRAMED = 54,
1042  VT_NOT_OVERLINED = 55,
1043  VT_NO_ATTR = 98,
1044  VT_UNKNOWN_ATTR = 99
1045 } vt_attr_e;
1046 
1047 struct vt_attrs {
1048  const char *name;
1049  vt_attr_e attr;
1050 };
1051 
1052 // clang-format off
1053 #define VT_ATTRS { \
1054  { "off", VT_OFF }, \
1055  { "bold", VT_BOLD }, \
1056  { "faint", VT_FAINT }, \
1057  { "italic", VT_ITALIC }, \
1058  { "underscore", VT_UNDERSCORE }, \
1059  { "blink", VT_SLOW_BLINK }, \
1060  { "fastblink", VT_FAST_BLINK }, \
1061  { "reverse", VT_REVERSE }, \
1062  { "concealed", VT_CONCEALED }, \
1063  { "crossout", VT_CROSSOUT }, \
1064  { "deffont", VT_DEFAULT_FONT }, \
1065  { "default", VT_NO_ATTR }, \
1066  { NULL, VT_UNKNOWN_ATTR } \
1067 }
1068 // clang-format on
1069 
1070 #define VT_BLINK VT_SLOW_BLINK
1071 
1072 #define ESC "\033"
1073 
1074 /* cursor codes */
1075 #define vt100_cursor_off ESC "[?25l"
1076 #define vt100_cursor_on ESC "[?25h"
1077 #define vt100_save_cursor ESC "7"
1078 #define vt100_restore_cursor ESC "8"
1079 #define vt100_line_feed ESC "D"
1080 #define vt100_crnl ESC "E"
1081 #define vt100_reverse_line_feed ESC "M"
1082 #define vt100_up_arr ESC "[A"
1083 #define vt100_down_arr ESC "[B"
1084 #define vt100_right_arr ESC "[C"
1085 #define vt100_left_arr ESC "[D"
1086 #define vt100_up_lines ESC "[%dA"
1087 #define vt100_down_lines ESC "[%dB"
1088 #define vt100_right_columns ESC "[%dC"
1089 #define vt100_left_columns ESC "[%dD"
1090 #define vt100_move_down_nlines ESC "[%dE"
1091 #define vt100_scroll_down ESC "[%dT"
1092 #define vt100_scroll_up ESC "[%dS"
1093 #define vt100_home ESC "[H"
1094 #define vt100_pos ESC "[%d;%dH"
1095 #define vt100_setw ESC "[%d;r"
1096 #define vt100_clear_right ESC "[0K"
1097 #define vt100_clear_left ESC "[1K"
1098 #define vt100_clear_down ESC "[0J"
1099 #define vt100_clear_up ESC "[1J"
1100 #define vt100_clear_line ESC "[2K"
1101 #define vt100_clear_screen ESC "[2J"
1102 #define vt100_pos_cursor ESC "[%d;%dH"
1103 #define vt100_multi_right ESC "\133%uC"
1104 #define vt100_multi_left ESC "\133%uD"
1105 #define vt100_cursor_pos ESC "[6n"
1106 #define vt100_clr_eol ESC "[K"
1107 #define vt100_clr_eos ESC "[J"
1108 
1109 // clang-format off
1110 #define _s(_x, _y) static __inline__ void _x { _y; }
1111 
1113 _s(vt_pos(int r, int c), tty_printf(vt100_pos, r, c))
1114 
1115 
1116 _s(vt_top(void), tty_printf(vt100_home))
1117 
1119 _s(vt_home(void), tty_printf(vt100_home))
1120 
1122 _s(vt_coff(void), tty_printf(vt100_cursor_off))
1123 
1125 _s(vt_con(void), tty_printf(vt100_cursor_on))
1126 
1128 _s(vt_turn_on(void), tty_printf(vt100_cursor_off))
1129 
1131 _s(vt_turn_off(void), tty_printf(vt100_cursor_on))
1132 
1134 _s(vt_save(void), tty_printf(vt100_save_cursor))
1135 
1137 _s(vt_restore(void), tty_printf(vt100_restore_cursor))
1138 
1140 _s(vt_eol(void), tty_printf(vt100_clr_eol))
1141 
1143 _s(vt_cbl(void), tty_printf(vt100_clear_left))
1144 
1146 _s(vt_cel(void), tty_printf(vt100_clear_line))
1147 
1149 _s(vt_clw(void), tty_printf(vt100_clr_eos))
1150 
1152 _s(vt_clb(void), tty_printf(vt100_clear_up))
1153 
1155 _s(vt_cls(void), tty_printf(vt100_clear_screen))
1156 
1158 _s(vt_reverse(void), tty_printf(ESC "[7m"))
1159 
1161 _s(vt_normal(void), tty_printf(ESC "[0m"))
1162 
1164 _s(vt_scroll(int r), tty_printf(vt100_scroll_up, r))
1165 
1167 _s(vt_scroll_up(int r), tty_printf(vt100_scroll_up, r))
1168 
1170 _s(vt_scroll_down(int r), tty_printf(vt100_scroll_down, r))
1171 
1173 _s(vt_nlines(int r), tty_printf(vt100_move_down_nlines, r))
1174 
1176 _s(vt_setw(int t), tty_printf(vt100_setw, t))
1177 
1179 _s(vt_cpos(void), tty_printf(vt100_cursor_pos))
1180 
1182 _s(vt_cup(int n), tty_printf(vt100_up_lines, n))
1183 
1185 _s(vt_cnright(int n), tty_printf(vt100_right_columns, n))
1186 
1188 _s(vt_cnleft(int n), tty_printf(vt100_left_columns, n))
1189 
1191 _s(vt_newline(void), tty_printf(ESC "[20h"))
1192 
1194 _s(vt_cright(void), tty_printf(vt100_right_arr))
1195 
1197 _s(vt_cleft(void), tty_printf(vt100_left_arr))
1198 
1200 _s(vt_bol(void), tty_printf("\r"))
1201 
1208 static __inline__ void
1209 vt_make_space(int n)
1210 {
1211  for (int i = 0; i < (n + 1); i++)
1212  tty_printf("\n");
1213  vt_cup(n + 1);
1214 }
1215 
1222 static __inline__ void
1224 {
1225  vt_pos(r, 0);
1226  vt_cel();
1227 }
1228 
1237 static __inline__ void
1238 vt_eol_pos(int r, int c)
1239 {
1240  vt_pos(r, c);
1241  vt_eol();
1242 }
1243 
1254 static __inline__ int
1255 vt_center_col(int16_t ncols, const char *msg)
1256 {
1257  int16_t s;
1258 
1259  s = ((ncols / 2) - (strlen(msg) / 2));
1260  return (s <= 0) ? 1 : s;
1261 }
1262 
1270 static __inline__ void
1271 vt_erase(int16_t nrows)
1272 {
1273  vt_setw(1); /* Clear the window to full screen. */
1274  vt_pos(nrows + 1, 1); /* Put cursor on the last row. */
1275  for(int i = 0; i < (nrows + 3); i += 4)
1276  tty_write("\n\n\n\n", 4);
1277 }
1278 
1291 static __inline__ void
1292 vt_repeat(int16_t r, int16_t c, const char *str, int cnt)
1293 {
1294  int i;
1295 
1296  vt_pos(r, c);
1297  for (i = 0; i < cnt; i++)
1298  tty_printf("%s", str);
1299 }
1300 
1313 static __inline__ void
1314 vt_col_repeat(int16_t r, int16_t c, const char *str, int cnt)
1315 {
1316  int i;
1317 
1318  for (i = 0; i < cnt; i++) {
1319  vt_pos(r++, c);
1320  tty_printf("%s", str);
1321  }
1322 }
1323 
1332 static __inline__ void
1334 {
1335  tty_printf(ESC "[%d;%dm", attr, color + 30);
1336 }
1337 
1346 static __inline__ void
1348 {
1349  tty_printf(ESC "[%d;%dm", attr, color + 40);
1350 }
1351 
1362 static __inline__ void
1364 {
1365  tty_printf(ESC "[%d;%d;%dm", attr, fg + 30, bg + 40);
1366 }
1367 
1378 static __inline__ void
1380 {
1381 
1382  if ((fg != VT_NO_CHANGE) && (bg != VT_NO_CHANGE))
1383  vt_fgbgcolor(fg, bg, attr);
1384  else if (fg == VT_NO_CHANGE)
1385  vt_bgcolor(bg, attr);
1386  else if (bg == VT_NO_CHANGE)
1387  vt_fgcolor(fg, attr);
1388 }
1389 
1402 static __inline__ void
1403 vt_rgb(uint8_t fg_bg, vt_rgb_t r, vt_rgb_t g, vt_rgb_t b)
1404 {
1405  tty_printf(ESC "[%d:2:%d:%d:%dm", fg_bg, r, g, b);
1406 }
1407 
1422 static __inline__ int
1423 vt_fgcolor_str(char *str, int len, vt_color_e color, vt_attr_e attr)
1424 {
1425  return snprintf(str, len, ESC "[%d;%dm", attr, color + 30);
1426 }
1427 
1442 static __inline__ int
1443 vt_bgcolor_str(char *str, int len, vt_color_e color, vt_attr_e attr)
1444 {
1445  return snprintf(str, len, ESC "[%d;%dm", attr, color + 40);
1446 }
1447 
1460 static __inline__ int
1461 vt_attr_str(char *str, int len, vt_attr_e attr)
1462 {
1463  return snprintf(str, len, ESC "[%dm", attr);
1464 }
1465 
1482 static __inline__ int
1483 vt_fgbgcolor_str(char *str, int len, vt_color_e fg, vt_color_e bg, vt_attr_e attr)
1484 {
1485  return snprintf(str, len, ESC "[%d;%d;%dm", attr, fg + 30, bg + 40);
1486 }
1487 
1505 static __inline__ int
1506 vt_color_str(char *str, int len, vt_color_e fg, vt_color_e bg, vt_attr_e attr)
1507 {
1508  if ((fg != VT_NO_CHANGE) && (bg != VT_NO_CHANGE))
1509  return vt_fgbgcolor_str(str, len, fg, bg, attr);
1510  else if (fg == VT_NO_CHANGE)
1511  return vt_bgcolor_str(str, len, bg, attr);
1512  else if (bg == VT_NO_CHANGE)
1513  return vt_fgcolor_str(str, len, fg, attr);
1514 
1515  return 0;
1516 }
1517 
1536 static __inline__ int
1537 vt_rgb_str(char *str, int len, uint8_t fg_bg, vt_rgb_t r, vt_rgb_t g, vt_rgb_t b)
1538 {
1539  return snprintf(str, len, ESC "[%d:2::%d:%d:%dm", fg_bg, r, g, b);
1540 }
1541 
1552 CNDP_API int vt_color_parse(char *buff, int len);
1553 
1554 #ifdef __cplusplus
1555 }
1556 #endif
1557 
1558 #endif /* __VT100_OUT_H_ */
CNDP_API int tty_write(const char *buf, int len)
static __inline__ int vt_fgcolor_str(char *str, int len, vt_color_e color, vt_attr_e attr)
Definition: vt100_out.h:1423
CNDP_API int vt_color_parse(char *buff, int len)
static __inline__ int vt_fgbgcolor_str(char *str, int len, vt_color_e fg, vt_color_e bg, vt_attr_e attr)
Definition: vt100_out.h:1483
_s(vt_pos(int r, int c), tty_printf(vt100_pos, r, c)) _s(vt_top(void)
static __inline__ void vt_fgbgcolor(vt_color_e fg, vt_color_e bg, vt_attr_e attr)
Definition: vt100_out.h:1363
static __inline__ void vt_clr_line(int r)
Definition: vt100_out.h:1223
static __inline__ void vt_eol_pos(int r, int c)
Definition: vt100_out.h:1238
static __inline__ void vt_rgb(uint8_t fg_bg, vt_rgb_t r, vt_rgb_t g, vt_rgb_t b)
Definition: vt100_out.h:1403
tty_printf(vt100_home)) _s(vt_home(void)
static __inline__ void vt_repeat(int16_t r, int16_t c, const char *str, int cnt)
Definition: vt100_out.h:1292
uint8_t vt_rgb_t
Definition: vt100_out.h:34
static __inline__ void vt_col_repeat(int16_t r, int16_t c, const char *str, int cnt)
Definition: vt100_out.h:1314
vt_color_e
Definition: vt100_out.h:38
static __inline__ void vt_fgcolor(vt_color_e color, vt_attr_e attr)
Definition: vt100_out.h:1333
static __inline__ int vt_bgcolor_str(char *str, int len, vt_color_e color, vt_attr_e attr)
Definition: vt100_out.h:1443
static __inline__ int vt_rgb_str(char *str, int len, uint8_t fg_bg, vt_rgb_t r, vt_rgb_t g, vt_rgb_t b)
Definition: vt100_out.h:1537
static __inline__ int vt_attr_str(char *str, int len, vt_attr_e attr)
Definition: vt100_out.h:1461
vt_attr_e
Definition: vt100_out.h:1020
static __inline__ int vt_color_str(char *str, int len, vt_color_e fg, vt_color_e bg, vt_attr_e attr)
Definition: vt100_out.h:1506
static __inline__ void vt_bgcolor(vt_color_e color, vt_attr_e attr)
Definition: vt100_out.h:1347
static __inline__ int vt_center_col(int16_t ncols, const char *msg)
Definition: vt100_out.h:1255
static __inline__ void vt_erase(int16_t nrows)
Definition: vt100_out.h:1271
static __inline__ void vt_color(vt_color_e fg, vt_color_e bg, vt_attr_e attr)
Definition: vt100_out.h:1379