-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansi.h
88 lines (77 loc) · 3.32 KB
/
ansi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*****************************************************************************
* ansi.h
*
* ANSI escapes macros
*
* ---------------------------------------------------------------------------
* ardccino - Arduino dual PWM/DCC controller
* (C) 2013-2015 Gerardo García Peña <killabytenow@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef __ANSI_H__
#define __ANSI_H__
#define ANSI_ESC "\x1B"
#define ANSI_CSI "\x1B["
#define ANSI_DCS "\x1BP"
#define ANSI_ST "\x1B\\"
// ED – Erase Display (cursor does not move)
// Clears part of the screen. If n is zero (or missing), clear from cursor to
// end of screen. If n is one, clear from cursor to beginning of the screen.
// If n is two, clear entire screen (and moves cursor to upper left on DOS
// ANSI.SYS).
#define ANSI_ED(x) ANSI_CSI #x "J"
// EL - Erase in Line (cursor does not move)
// [K [0K Erase from current position to end (inclusive)
// [1K Erase from beginning to current position
// [2K Erase entire current line
// [?0K Selective erase to end of line ([?1K, [?2K similar)
#define ANSI_EL(x) ANSI_CSI #x "K"
// SCP – Save Cursor Position
// RCP – Restore Cursor Position
// Saves/Restores the cursor position.
#define ANSI_SCP ANSI_CSI "s"
#define ANSI_RCP ANSI_CSI "u"
// CUU – Cursor Up
// CUD – Cursor Down
// CUF – Cursor Forward
// CUB – Cursor Back
// Moves the cursor n (default 1) cells in the given direction. If the cursor
// is already at the edge of the screen, this has no effect.
#define ANSI_CUU(n) ANSI_CSI #n "A"
#define ANSI_CUD(n) ANSI_CSI #n "B"
#define ANSI_CUF(n) ANSI_CSI #n "C"
#define ANSI_CUB(n) ANSI_CSI #n "D"
// CUP – Cursor Position
// HVP – Horizontal and Vertical Position (same as CUP)
// Moves the cursor to row n, column m. The values are 1-based, and default
// to 1 (top left corner) if omitted. A sequence such as CSI ;5H is a synonym
// for CSI 1;5H as well as CSI 17;H is the same as CSI 17H and CSI 17;1H
#define ANSI_CUP(x, y) ANSI_CSI #y ";" #x "H"
#define ANSI_HVP(x, y) ANSI_CSI #y ";" #x "f"
// SGR – Select Graphic Rendition
// Sets SGR parameters, including text color. After CSI can be zero or more
// parameters separated with ;. With no parameters, CSI m is treated as CSI 0
// m (reset / normal), which is typical of most of the ANSI escape sequences.
#define ANSI_SGR(x) ANSI_CSI #x "m"
// SGR COMMANDS
// Some macros based on SGR commands
#define ANSI_SGR_RESET ANSI_SGR(0)
#define ANSI_SGR_BOLD ANSI_SGR(2)
#define ANSI_SGR_BOLD_OFF ANSI_SGR(22)
// EXTRAS
#define ANSI_CLS ANSI_ED(1) ANSI_HVP(1,1)
#endif