TerminalCodes.h 8.79 KB
Newer Older
1
2
3
/*
             LUFA Library
     Copyright (C) Dean Camera, 2010.
4

5
  dean [at] fourwalledcubicle [dot] com
6
           www.lufa-lib.org
7
8
9
10
11
*/

/*
  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)

12
  Permission to use, copy, modify, distribute, and sell this
13
  software and its documentation for any purpose is hereby granted
14
  without fee, provided that the above copyright notice appear in
15
  all copies and that both that the copyright notice and this
16
17
18
  permission notice and warranty disclaimer appear in supporting
  documentation, and that the name of the author not be used in
  advertising or publicity pertaining to distribution of the
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  software without specific, written prior permission.

  The author disclaim all warranties with regard to this
  software, including all implied warranties of merchantability
  and fitness.  In no event shall the author be liable for any
  special, indirect or consequential damages or any damages
  whatsoever resulting from loss of use, data or profits, whether
  in an action of contract, negligence or other tortious action,
  arising out of or in connection with the use or performance of
  this software.
*/

/** \file
 *  \brief ANSI terminal special escape code macros.
 *
 *  ANSI terminal compatible escape sequences. These escape sequences are designed to be concatenated with existing
 *  strings to modify their display on a compatible terminal application.
 */
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
/** \ingroup Group_MiscDrivers
 *  @defgroup Group_Terminal ANSI Terminal Escape Codes - LUFA/Drivers/Misc/TerminalCodes.h
 *
 *  \section Sec_Dependencies Module Source Dependencies
 *  The following files must be built with any user project that uses this module:
 *    - None
 *
 *  \section Module Description
 *  Escape code macros for ANSI compliant text terminals.
 *
 *  \note If desired, the macro DISABLE_TERMINAL_CODES can be defined in the project makefile and passed to the GCC
 *        compiler via the -D switch to disable the terminal codes without modifying the source, for use with non
 *        compatible terminals (any terminal codes then equate to empty strings).
 *
52
 *  <b>Example Usage:</b>
53
54
55
56
57
58
 *  \code
 *      printf("Some String, " ESC_BOLD_ON " Some bold string");
 *  \endcode
 *
 *  @{
 */
59

60
61
62
63
64
65
#ifndef __TERMINALCODES_H__
#define __TERMINALCODES_H__

	/* Public Interface - May be used in end-application: */
		/* Macros: */
			#if !defined(DISABLE_TERMINAL_CODES)
66
				/** Creates an ANSI escape sequence with the specified payload.
67
				 *
68
				 *  \param[in] EscapeSeq  Payload to encode as an ANSI escape sequence, a ESC_* mask.
69
				 */
70
				#define ANSI_ESCAPE_SEQUENCE(EscapeSeq)  "\33[" EscapeSeq
71
			#else
72
				#define ANSI_ESCAPE_SEQUENCE(EscapeSeq)
73
74
			#endif

75
76
			/** \name Text Display Modifier Escape Sequences */
			//@{
77
			/** Turns on bold so that any following text is printed to the terminal in bold. */
78
			#define ESC_BOLD_ON                     ANSI_ESCAPE_SEQUENCE("1m")
79
80

			/** Turns on italics so that any following text is printed to the terminal in italics. */
81
			#define ESC_ITALICS_ON                  ANSI_ESCAPE_SEQUENCE("3m")
82
83

			/** Turns on underline so that any following text is printed to the terminal underlined. */
84
			#define ESC_UNDERLINE_ON                ANSI_ESCAPE_SEQUENCE("4m")
85
86

			/** Turns on inverse so that any following text is printed to the terminal in inverted colours. */
87
			#define ESC_INVERSE_ON                  ANSI_ESCAPE_SEQUENCE("7m")
88
89
90
91

			/** Turns on strikethrough so that any following text is printed to the terminal with a line through the
			 *  center.
			 */
92
			#define ESC_STRIKETHROUGH_ON            ANSI_ESCAPE_SEQUENCE("9m")
93
94

			/** Turns off bold so that any following text is printed to the terminal in non bold. */
95
			#define ESC_BOLD_OFF                    ANSI_ESCAPE_SEQUENCE("22m")
96
97

			/** Turns off italics so that any following text is printed to the terminal in non italics. */
98
			#define ESC_ITALICS_OFF                 ANSI_ESCAPE_SEQUENCE("23m")
99
100

			/** Turns off underline so that any following text is printed to the terminal non underlined. */
101
			#define ESC_UNDERLINE_OFF               ANSI_ESCAPE_SEQUENCE("24m")
102
103

			/** Turns off inverse so that any following text is printed to the terminal in non inverted colours. */
104
			#define ESC_INVERSE_OFF                 ANSI_ESCAPE_SEQUENCE("27m")
105
106
107
108

			/** Turns off strikethrough so that any following text is printed to the terminal without a line through
			 *  the center.
			 */
109
			#define ESC_STRIKETHROUGH_OFF           ANSI_ESCAPE_SEQUENCE("29m")
110
111
112
113
			//@}
			
			/** \name Text Colour Control Sequences */
			//@{
114
			/** Sets the foreground (text) colour to black. */
115
			#define ESC_FG_BLACK                    ANSI_ESCAPE_SEQUENCE("30m")
116
117

			/** Sets the foreground (text) colour to red. */
118
			#define ESC_FG_RED                      ANSI_ESCAPE_SEQUENCE("31m")
119
120

			/** Sets the foreground (text) colour to green. */
121
			#define ESC_FG_GREEN                    ANSI_ESCAPE_SEQUENCE("32m")
122
123

			/** Sets the foreground (text) colour to yellow. */
124
			#define ESC_FG_YELLOW                   ANSI_ESCAPE_SEQUENCE("33m")
125
126

			/** Sets the foreground (text) colour to blue. */
127
			#define ESC_FG_BLUE                     ANSI_ESCAPE_SEQUENCE("34m")
128
129

			/** Sets the foreground (text) colour to magenta. */
130
			#define ESC_FG_MAGENTA                  ANSI_ESCAPE_SEQUENCE("35m")
131
132

			/** Sets the foreground (text) colour to cyan. */
133
			#define ESC_FG_CYAN                     ANSI_ESCAPE_SEQUENCE("36m")
134
135

			/** Sets the foreground (text) colour to white. */
136
			#define ESC_FG_WHITE                    ANSI_ESCAPE_SEQUENCE("37m")
137
138

			/** Sets the foreground (text) colour to the terminal's default. */
139
			#define ESC_FG_DEFAULT                  ANSI_ESCAPE_SEQUENCE("39m")
140
141

			/** Sets the text background colour to black. */
142
			#define ESC_BG_BLACK                    ANSI_ESCAPE_SEQUENCE("40m")
143
144

			/** Sets the text background colour to red. */
145
			#define ESC_BG_RED                      ANSI_ESCAPE_SEQUENCE("41m")
146
147

			/** Sets the text background colour to green. */
148
			#define ESC_BG_GREEN                    ANSI_ESCAPE_SEQUENCE("42m")
149
150

			/** Sets the text background colour to yellow. */
151
			#define ESC_BG_YELLOW                   ANSI_ESCAPE_SEQUENCE("43m")
152
153

			/** Sets the text background colour to blue. */
154
			#define ESC_BG_BLUE                     ANSI_ESCAPE_SEQUENCE("44m")
155
156

			/** Sets the text background colour to magenta. */
157
			#define ESC_BG_MAGENTA                  ANSI_ESCAPE_SEQUENCE("45m")
158
159

			/** Sets the text background colour to cyan. */
160
			#define ESC_BG_CYAN                     ANSI_ESCAPE_SEQUENCE("46m")
161
162

			/** Sets the text background colour to white. */
163
			#define ESC_BG_WHITE                    ANSI_ESCAPE_SEQUENCE("47m")
164
165

			/** Sets the text background colour to the terminal's default. */
166
			#define ESC_BG_DEFAULT                  ANSI_ESCAPE_SEQUENCE("49m")
167
			//@}
168

169
170
			/** \name Cursor Positioning Control Sequences */
			//@{
171
172
			/** Saves the current cursor position so that it may be restored with \ref ESC_CURSOR_POS_RESTORE. */
			#define ESC_CURSOR_POS_SAVE             ANSI_ESCAPE_SEQUENCE("s")
173

174
175
			/** Restores the cursor position to the last position saved with \ref ESC_CURSOR_POS_SAVE. */
			#define ESC_CURSOR_POS_RESTORE          ANSI_ESCAPE_SEQUENCE("u")
176

177
178
179
180
181
182
			/** Sets the cursor position to the given line and column.
			 *
			 *  \param[in] Line    Line number to position the cursor at
			 *  \param[in] Column  Column number to position the cursor at
			 */
			#define ESC_CURSOR_POS(Line, Column)    ANSI_ESCAPE_SEQUENCE(#Line ";" #Column "H")
183

184
185
186
187
188
			/** Moves the cursor up the given number of lines.
			 *
			 *  \param[in] Lines  Number of lines to move the cursor position
			 */
			#define ESC_CURSOR_UP(Lines)            ANSI_ESCAPE_SEQUENCE(#Lines "A")
189

190
191
192
193
194
			/** Moves the cursor down the given number of lines.
			 *
			 *  \param[in] Lines  Number of lines to move the cursor position
			 */
			#define ESC_CURSOR_DOWN(Lines)          ANSI_ESCAPE_SEQUENCE(#Lines "B")
195

196
197
198
199
200
			/** Moves the cursor to the right the given number of columns.
			 *
			 *  \param[in] Columns  Number of columns to move the cursor position
			 */
			#define ESC_CURSOR_FORWARD(Columns)     ANSI_ESCAPE_SEQUENCE(#Columns "C")
201

202
203
204
205
206
			/** Moves the cursor to the left the given number of columns.
			 *
			 *  \param[in] Columns  Number of columns to move the cursor position
			 */
			#define ESC_CURSOR_BACKWARD(Columns)    ANSI_ESCAPE_SEQUENCE(#Columns "D")
207
208
209
210
211
			//@}

			/** \name Miscellaneous Control Sequences */
			//@{
			/** Resets any escape sequence modifiers back to their defaults. */
212
			#define ESC_RESET                       ANSI_ESCAPE_SEQUENCE("0m")
213

214
			/** Erases the entire display, returning the cursor to the top left. */
215
			#define ESC_ERASE_DISPLAY               ANSI_ESCAPE_SEQUENCE("2J")
216
217

			/** Erases the current line, returning the cursor to the far left. */
218
			#define ESC_ERASE_LINE                  ANSI_ESCAPE_SEQUENCE("K")
219
			//@}
220
221
222
223

#endif

/** @} */
224