Update copyright year on all source files.
[pub/USBasp.git] / LUFA / Drivers / Misc / TerminalCodes.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 * \brief ANSI terminal special escape code macros.
33 *
34 * ANSI terminal compatible escape sequences. These escape sequences are designed to be concatenated with existing
35 * strings to modify their display on a compatible terminal application.
36 */
37
38 /** \ingroup Group_MiscDrivers
39 * @defgroup Group_Terminal ANSI Terminal Escape Codes - LUFA/Drivers/Misc/TerminalCodes.h
40 *
41 * \section Sec_Dependencies Module Source Dependencies
42 * The following files must be built with any user project that uses this module:
43 * - None
44 *
45 * \section Sec_ModDescription Module Description
46 * Escape code macros for ANSI compliant text terminals.
47 *
48 * \note If desired, the macro DISABLE_TERMINAL_CODES can be defined in the project makefile and passed to the GCC
49 * compiler via the -D switch to disable the terminal codes without modifying the source, for use with non
50 * compatible terminals (any terminal codes then equate to empty strings).
51 *
52 * \section Sec_ExampleUsage Example Usage
53 * The following snippet is an example of how this module may be used within a typical
54 * application.
55 *
56 * \code
57 * printf("Normal String, "
58 * ESC_BOLD_ON "Bold String, "
59 * ESC_UNDERLINE_ON "Bold and Underlined String"
60 * ESC_RESET ESC_FG_BLUE ESC_BG_YELLOW "Normal Blue-on-Yellow String");
61 * \endcode
62 *
63 * @{
64 */
65
66 #ifndef __TERMINALCODES_H__
67 #define __TERMINALCODES_H__
68
69 /* Public Interface - May be used in end-application: */
70 /* Macros: */
71 #if !defined(DISABLE_TERMINAL_CODES)
72 /** Creates an ANSI escape sequence with the specified payload.
73 *
74 * \param[in] EscapeSeq Payload to encode as an ANSI escape sequence, a ESC_* mask.
75 */
76 #define ANSI_ESCAPE_SEQUENCE(EscapeSeq) "\33[" EscapeSeq
77 #else
78 #define ANSI_ESCAPE_SEQUENCE(EscapeSeq)
79 #endif
80
81 /** \name Text Display Modifier Escape Sequences */
82 //@{
83 /** Turns on bold so that any following text is printed to the terminal in bold. */
84 #define ESC_BOLD_ON ANSI_ESCAPE_SEQUENCE("1m")
85
86 /** Turns on italics so that any following text is printed to the terminal in italics. */
87 #define ESC_ITALICS_ON ANSI_ESCAPE_SEQUENCE("3m")
88
89 /** Turns on underline so that any following text is printed to the terminal underlined. */
90 #define ESC_UNDERLINE_ON ANSI_ESCAPE_SEQUENCE("4m")
91
92 /** Turns on inverse so that any following text is printed to the terminal in inverted colours. */
93 #define ESC_INVERSE_ON ANSI_ESCAPE_SEQUENCE("7m")
94
95 /** Turns on strikethrough so that any following text is printed to the terminal with a line through the
96 * center.
97 */
98 #define ESC_STRIKETHROUGH_ON ANSI_ESCAPE_SEQUENCE("9m")
99
100 /** Turns off bold so that any following text is printed to the terminal in non bold. */
101 #define ESC_BOLD_OFF ANSI_ESCAPE_SEQUENCE("22m")
102
103 /** Turns off italics so that any following text is printed to the terminal in non italics. */
104 #define ESC_ITALICS_OFF ANSI_ESCAPE_SEQUENCE("23m")
105
106 /** Turns off underline so that any following text is printed to the terminal non underlined. */
107 #define ESC_UNDERLINE_OFF ANSI_ESCAPE_SEQUENCE("24m")
108
109 /** Turns off inverse so that any following text is printed to the terminal in non inverted colours. */
110 #define ESC_INVERSE_OFF ANSI_ESCAPE_SEQUENCE("27m")
111
112 /** Turns off strikethrough so that any following text is printed to the terminal without a line through
113 * the center.
114 */
115 #define ESC_STRIKETHROUGH_OFF ANSI_ESCAPE_SEQUENCE("29m")
116 //@}
117
118 /** \name Text Colour Control Sequences */
119 //@{
120 /** Sets the foreground (text) colour to black. */
121 #define ESC_FG_BLACK ANSI_ESCAPE_SEQUENCE("30m")
122
123 /** Sets the foreground (text) colour to red. */
124 #define ESC_FG_RED ANSI_ESCAPE_SEQUENCE("31m")
125
126 /** Sets the foreground (text) colour to green. */
127 #define ESC_FG_GREEN ANSI_ESCAPE_SEQUENCE("32m")
128
129 /** Sets the foreground (text) colour to yellow. */
130 #define ESC_FG_YELLOW ANSI_ESCAPE_SEQUENCE("33m")
131
132 /** Sets the foreground (text) colour to blue. */
133 #define ESC_FG_BLUE ANSI_ESCAPE_SEQUENCE("34m")
134
135 /** Sets the foreground (text) colour to magenta. */
136 #define ESC_FG_MAGENTA ANSI_ESCAPE_SEQUENCE("35m")
137
138 /** Sets the foreground (text) colour to cyan. */
139 #define ESC_FG_CYAN ANSI_ESCAPE_SEQUENCE("36m")
140
141 /** Sets the foreground (text) colour to white. */
142 #define ESC_FG_WHITE ANSI_ESCAPE_SEQUENCE("37m")
143
144 /** Sets the foreground (text) colour to the terminal's default. */
145 #define ESC_FG_DEFAULT ANSI_ESCAPE_SEQUENCE("39m")
146
147 /** Sets the text background colour to black. */
148 #define ESC_BG_BLACK ANSI_ESCAPE_SEQUENCE("40m")
149
150 /** Sets the text background colour to red. */
151 #define ESC_BG_RED ANSI_ESCAPE_SEQUENCE("41m")
152
153 /** Sets the text background colour to green. */
154 #define ESC_BG_GREEN ANSI_ESCAPE_SEQUENCE("42m")
155
156 /** Sets the text background colour to yellow. */
157 #define ESC_BG_YELLOW ANSI_ESCAPE_SEQUENCE("43m")
158
159 /** Sets the text background colour to blue. */
160 #define ESC_BG_BLUE ANSI_ESCAPE_SEQUENCE("44m")
161
162 /** Sets the text background colour to magenta. */
163 #define ESC_BG_MAGENTA ANSI_ESCAPE_SEQUENCE("45m")
164
165 /** Sets the text background colour to cyan. */
166 #define ESC_BG_CYAN ANSI_ESCAPE_SEQUENCE("46m")
167
168 /** Sets the text background colour to white. */
169 #define ESC_BG_WHITE ANSI_ESCAPE_SEQUENCE("47m")
170
171 /** Sets the text background colour to the terminal's default. */
172 #define ESC_BG_DEFAULT ANSI_ESCAPE_SEQUENCE("49m")
173 //@}
174
175 /** \name Cursor Positioning Control Sequences */
176 //@{
177 /** Saves the current cursor position so that it may be restored with \ref ESC_CURSOR_POS_RESTORE. */
178 #define ESC_CURSOR_POS_SAVE ANSI_ESCAPE_SEQUENCE("s")
179
180 /** Restores the cursor position to the last position saved with \ref ESC_CURSOR_POS_SAVE. */
181 #define ESC_CURSOR_POS_RESTORE ANSI_ESCAPE_SEQUENCE("u")
182
183 /** Sets the cursor position to the given line and column.
184 *
185 * \param[in] Line Line number to position the cursor at.
186 * \param[in] Column Column number to position the cursor at.
187 */
188 #define ESC_CURSOR_POS(Line, Column) ANSI_ESCAPE_SEQUENCE(#Line ";" #Column "H")
189
190 /** Moves the cursor up the given number of lines.
191 *
192 * \param[in] Lines Number of lines to move the cursor position
193 */
194 #define ESC_CURSOR_UP(Lines) ANSI_ESCAPE_SEQUENCE(#Lines "A")
195
196 /** Moves the cursor down the given number of lines.
197 *
198 * \param[in] Lines Number of lines to move the cursor position
199 */
200 #define ESC_CURSOR_DOWN(Lines) ANSI_ESCAPE_SEQUENCE(#Lines "B")
201
202 /** Moves the cursor to the right the given number of columns.
203 *
204 * \param[in] Columns Number of columns to move the cursor position
205 */
206 #define ESC_CURSOR_FORWARD(Columns) ANSI_ESCAPE_SEQUENCE(#Columns "C")
207
208 /** Moves the cursor to the left the given number of columns.
209 *
210 * \param[in] Columns Number of columns to move the cursor position
211 */
212 #define ESC_CURSOR_BACKWARD(Columns) ANSI_ESCAPE_SEQUENCE(#Columns "D")
213 //@}
214
215 /** \name Miscellaneous Control Sequences */
216 //@{
217 /** Resets any escape sequence modifiers back to their defaults. */
218 #define ESC_RESET ANSI_ESCAPE_SEQUENCE("0m")
219
220 /** Erases the entire display, returning the cursor to the top left. */
221 #define ESC_ERASE_DISPLAY ANSI_ESCAPE_SEQUENCE("2J")
222
223 /** Erases the current line, returning the cursor to the far left. */
224 #define ESC_ERASE_LINE ANSI_ESCAPE_SEQUENCE("K")
225 //@}
226
227 #endif
228
229 /** @} */
230