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