MySQL 9.1.0
Source Code Documentation
vt100.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLHARNESS_VT100_INCLUDED
27#define MYSQLHARNESS_VT100_INCLUDED
28
29#include "harness_export.h"
30
31#include <array>
32#include <cstdint>
33#include <string>
34#include <tuple>
35
36// ECMA-48 -> ANSI X3.64 -> ISO 6429 ... implemented as VT100 by Digital
37//
38// https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
39//
40// https://www.xfree86.org/4.8.0/ctlseqs.html
41namespace Vt100 {
42/**
43 * colors as used in Render.
44 */
45enum class Color {
46 Black = 0,
47 Red,
48 Green,
49 Yellow,
50 Blue,
51 Magenta,
52 Cyan,
53 White,
54 BrightBlack = 60 + Black,
55 BrightRed = 60 + Red,
56 BrightGreen = 60 + Green,
57 BrightYellow = 60 + Yellow,
58 BrightBlue = 60 + Blue,
60 BrightCyan = 60 + Cyan,
61 BrightWhite = 60 + White
62};
63
64namespace {
65constexpr uint8_t kRenderForegroundOffset = 30;
67} // namespace
68
69/**
70 * types of "Character Attributes".
71 */
72enum class Render {
73 Default = 0,
74 Bold = 1,
75 Faint = 2, // not win32, not xterm
76 Italic = 3, // not win32, not xterm
77 Underline = 4,
78 SlowBlink = 5, // not win32
79 RapidBlink = 6, // not xterm
80 Inverse = 7,
81 Conceal = 8,
82 CrossedOut = 9, // not xterm
83
84 FontDefault = 10,
85 Font1 = 11,
86 Font2 = 12,
87 Font3 = 13,
88 Font4 = 14,
89 Font5 = 15,
90 Font6 = 16,
91 Font7 = 17,
92 Font8 = 18,
93 Font9 = 19,
94
95 Fraktur = 20, // not xterm
96 DoublyUnderline = 21, // not xterm
97 Normal = 22,
98 NoItalic = 20 + Italic, // not xterm
100 NoBlink = 20 + SlowBlink,
101 NoInverse = 20 + Inverse, // not xterm
102 NoConceal = 20 + Conceal,
103 NoCrossedOut = 20 + CrossedOut, // not xterm
104
105 // 30..39
106
113 kRenderForegroundOffset + static_cast<int>(Color::Magenta),
118
119 // 40..49
120
127 kRenderBackgroundOffset + static_cast<int>(Color::Magenta),
132
133 Framed = 51,
134 Encircled = 52,
135 Overlined = 53,
136 NotFramed = 54,
137 NotOverlined = 55,
140 IdeogramOverline = 62,
143 NoIdeogram = 65,
144
145 // 90..97
146
150 kRenderForegroundOffset + static_cast<int>(Color::BrightRed),
156 kRenderForegroundOffset + static_cast<int>(Color::BrightBlue),
160 kRenderForegroundOffset + static_cast<int>(Color::BrightCyan),
163
164 // 100..107
165
169 kRenderBackgroundOffset + static_cast<int>(Color::BrightRed),
175 kRenderBackgroundOffset + static_cast<int>(Color::BrightBlue),
179 kRenderBackgroundOffset + static_cast<int>(Color::BrightCyan),
182};
183
184using value_type = uint16_t;
185
186enum class Csi {
187 // insert char
188 ICH = '@',
189 // cursor up
190 CUU = 'A',
191 // cursor down
192 CUD = 'B',
193 // cursor forward
194 CUF = 'C',
195 // cursor backward
196 CUB = 'D',
197 // next line
198 CNL = 'E',
199 // prev line
200 CPL = 'F',
201 // cursor horizontal absolute
202 CHA = 'G',
203 // cursor position absolute
204 CUP = 'H',
205 // cursor tab forward
206 CHT = 'I',
207 // erase in display
208 ED = 'J',
209 // erase in line
210 EL = 'K',
211 // insert line
212 IL = 'L',
213 // delete line
214 DL = 'M',
215 // delete char
216 DCH = 'P',
217 // scroll up
218 SU = 'S',
219 // scroll down
220 SD = 'T',
221 // erase char
222 ECH = 'X',
223 // cursor tab backwards
224 CBT = 'Z',
225 // device attributes
226 DA = 'c',
227 // vertical
228 VPA = 'd',
229 // horizontal vertical position (same as CUP?)
230 HVP = 'f',
231 // tab clear
232 TBC = 'g',
233 // set mode
234 SM = 'h',
235 // Media Copy
236 MC = 'i',
237 // reset mode
238 RM = 'l',
239 // render
240 SGR = 'm',
241 // Device Status Report
242 DSR = 'n',
243 // Soft Terminal Reset
244 STR = 'p',
245 // set scrolling margins
246 DECSTBM = 'r',
247 // save cursor
248 SC = 's',
249 // Reverse Attributes in Rectangular Area
250 DECRARA = 't',
251 // restore cursor
252 SR = 'u',
253 DECCRA = 'v',
254 DECEFR = 'w',
255 // DECREQTPARM and others
256 DECREQTPARM = 'x',
257 // DECERA and others
258 DECERA = 'z',
259 DECSLE = '{',
260 DECRQLP = '|',
261};
262
263using Rgb = std::array<uint8_t, 3>;
264
265// high-level functions
266
267enum class Erase { LeftAndCur = 0, RightAndCur, All };
268
269/**
270 * get 'text rendering attributes' ESC sequence.
271 *
272 * SGR
273 */
274std::string HARNESS_EXPORT render(Render r);
275
276/**
277 * get 'change foreground color' ESC sequence.
278 */
279std::string HARNESS_EXPORT foreground(Color c);
280
281/**
282 * get 'change foreground color' ESC sequence.
283 */
284std::string HARNESS_EXPORT foreground(const Rgb &rgb);
285
286/**
287 * get 'change foreground color ESC' sequence.
288 */
289std::string HARNESS_EXPORT foreground(uint8_t ndx);
290
291/**
292 * get 'change background color' ESC sequence.
293 */
294std::string HARNESS_EXPORT background(Color c);
295
296/**
297 * get 'change background color' ESC sequence.
298 */
299std::string HARNESS_EXPORT background(const Rgb &rgb);
300
301/**
302 * get 'change background color' ESC sequence.
303 */
304std::string HARNESS_EXPORT background(uint8_t ndx);
305
306/**
307 * get 'reset attributes' ESC sequence.
308 */
309std::string HARNESS_EXPORT reset();
310
311/**
312 * get 'cursor up' ESC sequence.
313 */
314std::string HARNESS_EXPORT cursor_up(Vt100::value_type n = 1);
315
316/**
317 * get 'cursor down' ESC sequence.
318 */
319std::string HARNESS_EXPORT cursor_down(Vt100::value_type n = 1);
320
321/**
322 * get 'cursor forward' ESC sequence.
323 */
324std::string HARNESS_EXPORT cursor_forward(Vt100::value_type n = 1);
325
326/**
327 * get 'cursor back' ESC sequence.
328 */
329std::string HARNESS_EXPORT cursor_back(Vt100::value_type n = 1);
330
331/**
332 * get 'cursor next line' ESC sequence.
333 */
334std::string HARNESS_EXPORT cursor_next_line(Vt100::value_type n = 1);
335
336/**
337 * get 'cursor previous line' ESC sequence.
338 */
339std::string HARNESS_EXPORT cursor_prev_line(Vt100::value_type n = 1);
340
341/**
342 * get 'set cursor absolute position' ESC sequence.
343 */
344std::string HARNESS_EXPORT cursor_abs_col(Vt100::value_type col = 1);
345
346/**
347 * get 'set cursor absolute row' ESC sequence.
348 */
349std::string HARNESS_EXPORT cursor_abs_row(Vt100::value_type row = 1);
350
351/**
352 * get 'set cursor to absolute row' ESC sequence.
353 */
354std::string HARNESS_EXPORT cursor_abs_pos(Vt100::value_type row = 1,
355 Vt100::value_type col = 1);
356/**
357 * get 'erase in display' ESC sequence.
358 */
359std::string HARNESS_EXPORT
361
362/**
363 * get 'erase in line' ESC sequence.
364 */
365std::string HARNESS_EXPORT
367
368/**
369 * get 'scroll up' ESC sequence.
370 */
371std::string HARNESS_EXPORT scroll_up(Vt100::value_type n = 1);
372
373/**
374 * get 'scroll down' ESC sequence.
375 */
376std::string HARNESS_EXPORT scroll_down(Vt100::value_type n = 1);
377
378/**
379 * get 'save cursor position' ESC sequence.
380 */
381std::string HARNESS_EXPORT save_cursor_pos();
382
383/**
384 * get 'restore cursor position' ESC sequence.
385 */
386std::string HARNESS_EXPORT restore_cursor_pos();
387
388/**
389 * get 'set window title' ESC sequence.
390 */
391std::string HARNESS_EXPORT window_title(const std::string &title);
392} // namespace Vt100
393
394#endif
constexpr uint8_t kRenderBackgroundOffset
Definition: vt100.h:66
constexpr uint8_t kRenderForegroundOffset
Definition: vt100.h:65
Definition: vt100.h:41
Color
colors as used in Render.
Definition: vt100.h:45
std::string HARNESS_EXPORT cursor_forward(Vt100::value_type n=1)
get 'cursor forward' ESC sequence.
Definition: vt100.cc:76
uint16_t value_type
Definition: vt100.h:184
Erase
Definition: vt100.h:267
std::string HARNESS_EXPORT save_cursor_pos()
get 'save cursor position' ESC sequence.
Definition: vt100.cc:110
std::string HARNESS_EXPORT cursor_abs_col(Vt100::value_type col=1)
get 'set cursor absolute position' ESC sequence.
Definition: vt100.cc:88
std::string HARNESS_EXPORT cursor_down(Vt100::value_type n=1)
get 'cursor down' ESC sequence.
Definition: vt100.cc:73
std::string HARNESS_EXPORT reset()
get 'reset attributes' ESC sequence.
Definition: vt100.cc:37
std::string HARNESS_EXPORT window_title(const std::string &title)
get 'set window title' ESC sequence.
Definition: vt100.cc:113
std::string HARNESS_EXPORT scroll_down(Vt100::value_type n=1)
get 'scroll down' ESC sequence.
Definition: vt100.cc:107
Csi
Definition: vt100.h:186
std::string HARNESS_EXPORT erase_in_line(Vt100::Erase n=Vt100::Erase::LeftAndCur)
get 'erase in line' ESC sequence.
Definition: vt100.cc:101
std::string HARNESS_EXPORT scroll_up(Vt100::value_type n=1)
get 'scroll up' ESC sequence.
Definition: vt100.cc:104
std::string HARNESS_EXPORT cursor_abs_row(Vt100::value_type row=1)
get 'set cursor absolute row' ESC sequence.
Definition: vt100.cc:91
std::string HARNESS_EXPORT cursor_next_line(Vt100::value_type n=1)
get 'cursor next line' ESC sequence.
Definition: vt100.cc:82
std::string HARNESS_EXPORT render(Render r)
get 'text rendering attributes' ESC sequence.
Definition: vt100.cc:129
std::string HARNESS_EXPORT cursor_back(Vt100::value_type n=1)
get 'cursor back' ESC sequence.
Definition: vt100.cc:79
Render
types of "Character Attributes".
Definition: vt100.h:72
std::string HARNESS_EXPORT restore_cursor_pos()
get 'restore cursor position' ESC sequence.
Definition: vt100.cc:111
std::string HARNESS_EXPORT erase_in_display(Vt100::Erase n=Vt100::Erase::LeftAndCur)
get 'erase in display' ESC sequence.
Definition: vt100.cc:98
std::string HARNESS_EXPORT cursor_abs_pos(Vt100::value_type row=1, Vt100::value_type col=1)
get 'set cursor to absolute row' ESC sequence.
Definition: vt100.cc:94
std::string HARNESS_EXPORT cursor_up(Vt100::value_type n=1)
get 'cursor up' ESC sequence.
Definition: vt100.cc:70
std::string HARNESS_EXPORT foreground(Color c)
get 'change foreground color' ESC sequence.
Definition: vt100.cc:133
std::array< uint8_t, 3 > Rgb
Definition: vt100.h:263
std::string HARNESS_EXPORT background(Color c)
get 'change background color' ESC sequence.
Definition: vt100.cc:149
std::string HARNESS_EXPORT cursor_prev_line(Vt100::value_type n=1)
get 'cursor previous line' ESC sequence.
Definition: vt100.cc:85
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
int n
Definition: xcom_base.cc:509