3 Copyright (C) Dean Camera, 2019.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2019 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 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.
21 The author disclaims 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
32 * \brief ANSI terminal special escape code macros.
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.
38 /** \ingroup Group_MiscDrivers
39 * \defgroup Group_Terminal ANSI Terminal Escape Codes - LUFA/Drivers/Misc/TerminalCodes.h
40 * \brief ANSI terminal special escape code macros.
42 * \section Sec_Terminal_Dependencies Module Source Dependencies
43 * The following files must be built with any user project that uses this module:
46 * \section Sec_Terminal_ModDescription Module Description
47 * Escape code macros for ANSI compliant text terminals.
49 * \note If desired, the macro \c DISABLE_TERMINAL_CODES can be defined in the project makefile and passed to the GCC
50 * compiler via the -D switch to disable the terminal codes without modifying the source, for use with non
51 * compatible terminals (any terminal codes then equate to empty strings).
53 * \section Sec_Terminal_ExampleUsage Example Usage
54 * The following snippet is an example of how this module may be used within a typical
58 * printf("Normal String, "
59 * ESC_BOLD_ON "Bold String, "
60 * ESC_UNDERLINE_ON "Bold and Underlined String"
61 * ESC_RESET ESC_FG_BLUE ESC_BG_YELLOW "Normal Blue-on-Yellow String");
67 #ifndef __TERMINALCODES_H__
68 #define __TERMINALCODES_H__
70 /* Public Interface - May be used in end-application: */
72 #if !defined(DISABLE_TERMINAL_CODES)
73 /** Creates an ANSI escape sequence with the specified payload.
75 * \param[in] EscapeSeq Payload to encode as an ANSI escape sequence, a \c ESC_* mask.
77 #define ANSI_ESCAPE_SEQUENCE(EscapeSeq) "\33[" EscapeSeq
79 #define ANSI_ESCAPE_SEQUENCE(EscapeSeq)
82 /** \name Text Display Modifier Control Sequences */
84 /** Turns on bold so that any following text is printed to the terminal in bold. */
85 #define ESC_BOLD_ON ANSI_ESCAPE_SEQUENCE("1m")
87 /** Turns on italics so that any following text is printed to the terminal in italics. */
88 #define ESC_ITALICS_ON ANSI_ESCAPE_SEQUENCE("3m")
90 /** Turns on underline so that any following text is printed to the terminal underlined. */
91 #define ESC_UNDERLINE_ON ANSI_ESCAPE_SEQUENCE("4m")
93 /** Turns on inverse so that any following text is printed to the terminal in inverted colours. */
94 #define ESC_INVERSE_ON ANSI_ESCAPE_SEQUENCE("7m")
96 /** Turns on strike-through so that any following text is printed to the terminal with a line through the
99 #define ESC_STRIKETHROUGH_ON ANSI_ESCAPE_SEQUENCE("9m")
101 /** Turns off bold so that any following text is printed to the terminal in non bold. */
102 #define ESC_BOLD_OFF ANSI_ESCAPE_SEQUENCE("22m")
104 /** Turns off italics so that any following text is printed to the terminal in non italics. */
105 #define ESC_ITALICS_OFF ANSI_ESCAPE_SEQUENCE("23m")
107 /** Turns off underline so that any following text is printed to the terminal non underlined. */
108 #define ESC_UNDERLINE_OFF ANSI_ESCAPE_SEQUENCE("24m")
110 /** Turns off inverse so that any following text is printed to the terminal in non inverted colours. */
111 #define ESC_INVERSE_OFF ANSI_ESCAPE_SEQUENCE("27m")
113 /** Turns off strike-through so that any following text is printed to the terminal without a line through
116 #define ESC_STRIKETHROUGH_OFF ANSI_ESCAPE_SEQUENCE("29m")
119 /** \name Text Colour Control Sequences */
121 /** Sets the foreground (text) colour to black. */
122 #define ESC_FG_BLACK ANSI_ESCAPE_SEQUENCE("30m")
124 /** Sets the foreground (text) colour to red. */
125 #define ESC_FG_RED ANSI_ESCAPE_SEQUENCE("31m")
127 /** Sets the foreground (text) colour to green. */
128 #define ESC_FG_GREEN ANSI_ESCAPE_SEQUENCE("32m")
130 /** Sets the foreground (text) colour to yellow. */
131 #define ESC_FG_YELLOW ANSI_ESCAPE_SEQUENCE("33m")
133 /** Sets the foreground (text) colour to blue. */
134 #define ESC_FG_BLUE ANSI_ESCAPE_SEQUENCE("34m")
136 /** Sets the foreground (text) colour to magenta. */
137 #define ESC_FG_MAGENTA ANSI_ESCAPE_SEQUENCE("35m")
139 /** Sets the foreground (text) colour to cyan. */
140 #define ESC_FG_CYAN ANSI_ESCAPE_SEQUENCE("36m")
142 /** Sets the foreground (text) colour to white. */
143 #define ESC_FG_WHITE ANSI_ESCAPE_SEQUENCE("37m")
145 /** Sets the foreground (text) colour to the terminal's default. */
146 #define ESC_FG_DEFAULT ANSI_ESCAPE_SEQUENCE("39m")
148 /** Sets the text background colour to black. */
149 #define ESC_BG_BLACK ANSI_ESCAPE_SEQUENCE("40m")
151 /** Sets the text background colour to red. */
152 #define ESC_BG_RED ANSI_ESCAPE_SEQUENCE("41m")
154 /** Sets the text background colour to green. */
155 #define ESC_BG_GREEN ANSI_ESCAPE_SEQUENCE("42m")
157 /** Sets the text background colour to yellow. */
158 #define ESC_BG_YELLOW ANSI_ESCAPE_SEQUENCE("43m")
160 /** Sets the text background colour to blue. */
161 #define ESC_BG_BLUE ANSI_ESCAPE_SEQUENCE("44m")
163 /** Sets the text background colour to magenta. */
164 #define ESC_BG_MAGENTA ANSI_ESCAPE_SEQUENCE("45m")
166 /** Sets the text background colour to cyan. */
167 #define ESC_BG_CYAN ANSI_ESCAPE_SEQUENCE("46m")
169 /** Sets the text background colour to white. */
170 #define ESC_BG_WHITE ANSI_ESCAPE_SEQUENCE("47m")
172 /** Sets the text background colour to the terminal's default. */
173 #define ESC_BG_DEFAULT ANSI_ESCAPE_SEQUENCE("49m")
176 /** \name Cursor Positioning Control Sequences */
178 /** Saves the current cursor position so that it may be restored with \ref ESC_CURSOR_POS_RESTORE. */
179 #define ESC_CURSOR_POS_SAVE ANSI_ESCAPE_SEQUENCE("s")
181 /** Restores the cursor position to the last position saved with \ref ESC_CURSOR_POS_SAVE. */
182 #define ESC_CURSOR_POS_RESTORE ANSI_ESCAPE_SEQUENCE("u")
184 /** Sets the cursor position to the given line and column.
186 * \param[in] Line Line number to position the cursor at.
187 * \param[in] Column Column number to position the cursor at.
189 #define ESC_CURSOR_POS(Line, Column) ANSI_ESCAPE_SEQUENCE(#Line ";" #Column "H")
191 /** Moves the cursor up the given number of lines.
193 * \param[in] Lines Number of lines to move the cursor position
195 #define ESC_CURSOR_UP(Lines) ANSI_ESCAPE_SEQUENCE(#Lines "A")
197 /** Moves the cursor down the given number of lines.
199 * \param[in] Lines Number of lines to move the cursor position
201 #define ESC_CURSOR_DOWN(Lines) ANSI_ESCAPE_SEQUENCE(#Lines "B")
203 /** Moves the cursor to the right the given number of columns.
205 * \param[in] Columns Number of columns to move the cursor position
207 #define ESC_CURSOR_FORWARD(Columns) ANSI_ESCAPE_SEQUENCE(#Columns "C")
209 /** Moves the cursor to the left the given number of columns.
211 * \param[in] Columns Number of columns to move the cursor position
213 #define ESC_CURSOR_BACKWARD(Columns) ANSI_ESCAPE_SEQUENCE(#Columns "D")
216 /** \name Miscellaneous Control Sequences */
218 /** Resets any escape sequence modifiers back to their defaults. */
219 #define ESC_RESET ANSI_ESCAPE_SEQUENCE("0m")
221 /** Erases the entire display, returning the cursor to the top left. */
222 #define ESC_ERASE_DISPLAY ANSI_ESCAPE_SEQUENCE("2J")
224 /** Erases the current line, returning the cursor to the far left. */
225 #define ESC_ERASE_LINE ANSI_ESCAPE_SEQUENCE("K")