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