TerminalCodes.h 8.79 KB
 Dean Camera committed May 08, 2010 1 2 3 /* LUFA Library Copyright (C) Dean Camera, 2010.  4   Dean Camera committed May 08, 2010 5  dean [at] fourwalledcubicle [dot] com  Dean Camera committed Oct 28, 2010 6  www.lufa-lib.org  Dean Camera committed May 08, 2010 7 8 9 10 11 */ /* Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)  12  Permission to use, copy, modify, distribute, and sell this  Dean Camera committed May 08, 2010 13  software and its documentation for any purpose is hereby granted  14  without fee, provided that the above copyright notice appear in  Dean Camera committed May 08, 2010 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  Dean Camera committed May 08, 2010 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   Dean Camera committed May 08, 2010 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). *  Dean Camera committed Dec 26, 2010 52  * Example Usage:  Dean Camera committed May 08, 2010 53 54 55 56 57 58  * \code * printf("Some String, " ESC_BOLD_ON " Some bold string"); * \endcode * * @{ */  59   Dean Camera committed May 08, 2010 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)  Dean Camera committed Nov 17, 2010 66  /** Creates an ANSI escape sequence with the specified payload.  Dean Camera committed Jun 17, 2010 67  *  Dean Camera committed Nov 17, 2010 68  * \param[in] EscapeSeq Payload to encode as an ANSI escape sequence, a ESC_* mask.  Dean Camera committed Jun 17, 2010 69  */  Dean Camera committed Nov 17, 2010 70  #define ANSI_ESCAPE_SEQUENCE(EscapeSeq) "\33[" EscapeSeq  Dean Camera committed May 08, 2010 71  #else  Dean Camera committed Nov 17, 2010 72  #define ANSI_ESCAPE_SEQUENCE(EscapeSeq)  Dean Camera committed May 08, 2010 73 74  #endif  Dean Camera committed Oct 28, 2010 75 76  /** \name Text Display Modifier Escape Sequences */ //@{  Dean Camera committed May 08, 2010 77  /** Turns on bold so that any following text is printed to the terminal in bold. */  Dean Camera committed Nov 17, 2010 78  #define ESC_BOLD_ON ANSI_ESCAPE_SEQUENCE("1m")  Dean Camera committed May 08, 2010 79 80  /** Turns on italics so that any following text is printed to the terminal in italics. */  Dean Camera committed Nov 17, 2010 81  #define ESC_ITALICS_ON ANSI_ESCAPE_SEQUENCE("3m")  Dean Camera committed May 08, 2010 82 83  /** Turns on underline so that any following text is printed to the terminal underlined. */  Dean Camera committed Nov 17, 2010 84  #define ESC_UNDERLINE_ON ANSI_ESCAPE_SEQUENCE("4m")  Dean Camera committed May 08, 2010 85 86  /** Turns on inverse so that any following text is printed to the terminal in inverted colours. */  Dean Camera committed Nov 17, 2010 87  #define ESC_INVERSE_ON ANSI_ESCAPE_SEQUENCE("7m")  Dean Camera committed May 08, 2010 88 89 90 91  /** Turns on strikethrough so that any following text is printed to the terminal with a line through the * center. */  Dean Camera committed Nov 17, 2010 92  #define ESC_STRIKETHROUGH_ON ANSI_ESCAPE_SEQUENCE("9m")  Dean Camera committed May 08, 2010 93 94  /** Turns off bold so that any following text is printed to the terminal in non bold. */  Dean Camera committed Nov 17, 2010 95  #define ESC_BOLD_OFF ANSI_ESCAPE_SEQUENCE("22m")  Dean Camera committed May 08, 2010 96 97  /** Turns off italics so that any following text is printed to the terminal in non italics. */  Dean Camera committed Nov 17, 2010 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. */  Dean Camera committed Nov 17, 2010 101  #define ESC_UNDERLINE_OFF ANSI_ESCAPE_SEQUENCE("24m")  Dean Camera committed May 08, 2010 102 103  /** Turns off inverse so that any following text is printed to the terminal in non inverted colours. */  Dean Camera committed Nov 17, 2010 104  #define ESC_INVERSE_OFF ANSI_ESCAPE_SEQUENCE("27m")  Dean Camera committed May 08, 2010 105 106 107 108  /** Turns off strikethrough so that any following text is printed to the terminal without a line through * the center. */  Dean Camera committed Nov 17, 2010 109  #define ESC_STRIKETHROUGH_OFF ANSI_ESCAPE_SEQUENCE("29m")  Dean Camera committed Oct 28, 2010 110 111 112 113  //@} /** \name Text Colour Control Sequences */ //@{  Dean Camera committed May 08, 2010 114  /** Sets the foreground (text) colour to black. */  Dean Camera committed Nov 17, 2010 115  #define ESC_FG_BLACK ANSI_ESCAPE_SEQUENCE("30m")  Dean Camera committed May 08, 2010 116 117  /** Sets the foreground (text) colour to red. */  Dean Camera committed Nov 17, 2010 118  #define ESC_FG_RED ANSI_ESCAPE_SEQUENCE("31m")  Dean Camera committed May 08, 2010 119 120  /** Sets the foreground (text) colour to green. */  Dean Camera committed Nov 17, 2010 121  #define ESC_FG_GREEN ANSI_ESCAPE_SEQUENCE("32m")  Dean Camera committed May 08, 2010 122 123  /** Sets the foreground (text) colour to yellow. */  Dean Camera committed Nov 17, 2010 124  #define ESC_FG_YELLOW ANSI_ESCAPE_SEQUENCE("33m")  Dean Camera committed May 08, 2010 125 126  /** Sets the foreground (text) colour to blue. */  Dean Camera committed Nov 17, 2010 127  #define ESC_FG_BLUE ANSI_ESCAPE_SEQUENCE("34m")  Dean Camera committed May 08, 2010 128 129  /** Sets the foreground (text) colour to magenta. */  Dean Camera committed Nov 17, 2010 130  #define ESC_FG_MAGENTA ANSI_ESCAPE_SEQUENCE("35m")  Dean Camera committed May 08, 2010 131 132  /** Sets the foreground (text) colour to cyan. */  Dean Camera committed Nov 17, 2010 133  #define ESC_FG_CYAN ANSI_ESCAPE_SEQUENCE("36m")  Dean Camera committed May 08, 2010 134 135  /** Sets the foreground (text) colour to white. */  Dean Camera committed Nov 17, 2010 136  #define ESC_FG_WHITE ANSI_ESCAPE_SEQUENCE("37m")  Dean Camera committed May 08, 2010 137 138  /** Sets the foreground (text) colour to the terminal's default. */  Dean Camera committed Nov 17, 2010 139  #define ESC_FG_DEFAULT ANSI_ESCAPE_SEQUENCE("39m")  Dean Camera committed May 08, 2010 140 141  /** Sets the text background colour to black. */  Dean Camera committed Nov 17, 2010 142  #define ESC_BG_BLACK ANSI_ESCAPE_SEQUENCE("40m")  Dean Camera committed May 08, 2010 143 144  /** Sets the text background colour to red. */  Dean Camera committed Nov 17, 2010 145  #define ESC_BG_RED ANSI_ESCAPE_SEQUENCE("41m")  Dean Camera committed May 08, 2010 146 147  /** Sets the text background colour to green. */  Dean Camera committed Nov 17, 2010 148  #define ESC_BG_GREEN ANSI_ESCAPE_SEQUENCE("42m")  Dean Camera committed May 08, 2010 149 150  /** Sets the text background colour to yellow. */  Dean Camera committed Nov 17, 2010 151  #define ESC_BG_YELLOW ANSI_ESCAPE_SEQUENCE("43m")  Dean Camera committed May 08, 2010 152 153  /** Sets the text background colour to blue. */  Dean Camera committed Nov 17, 2010 154  #define ESC_BG_BLUE ANSI_ESCAPE_SEQUENCE("44m")  Dean Camera committed May 08, 2010 155 156  /** Sets the text background colour to magenta. */  Dean Camera committed Nov 17, 2010 157  #define ESC_BG_MAGENTA ANSI_ESCAPE_SEQUENCE("45m")  Dean Camera committed May 08, 2010 158 159  /** Sets the text background colour to cyan. */  Dean Camera committed Nov 17, 2010 160  #define ESC_BG_CYAN ANSI_ESCAPE_SEQUENCE("46m")  Dean Camera committed May 08, 2010 161 162  /** Sets the text background colour to white. */  Dean Camera committed Nov 17, 2010 163  #define ESC_BG_WHITE ANSI_ESCAPE_SEQUENCE("47m")  Dean Camera committed May 08, 2010 164 165  /** Sets the text background colour to the terminal's default. */  Dean Camera committed Nov 17, 2010 166  #define ESC_BG_DEFAULT ANSI_ESCAPE_SEQUENCE("49m")  Dean Camera committed Oct 28, 2010 167  //@}  168   Dean Camera committed Oct 28, 2010 169 170  /** \name Cursor Positioning Control Sequences */ //@{  Dean Camera committed Nov 17, 2010 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")  Dean Camera committed May 08, 2010 173   Dean Camera committed Nov 17, 2010 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")  Dean Camera committed May 08, 2010 176   Dean Camera committed Nov 17, 2010 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")  Dean Camera committed May 08, 2010 183   Dean Camera committed Nov 17, 2010 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")  Dean Camera committed May 08, 2010 189   Dean Camera committed Nov 17, 2010 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")  Dean Camera committed May 08, 2010 195   Dean Camera committed Nov 17, 2010 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")  Dean Camera committed May 08, 2010 201   Dean Camera committed Nov 17, 2010 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")  Dean Camera committed Oct 28, 2010 207 208 209 210 211  //@} /** \name Miscellaneous Control Sequences */ //@{ /** Resets any escape sequence modifiers back to their defaults. */  Dean Camera committed Nov 17, 2010 212  #define ESC_RESET ANSI_ESCAPE_SEQUENCE("0m")  213   Dean Camera committed May 08, 2010 214  /** Erases the entire display, returning the cursor to the top left. */  Dean Camera committed Nov 17, 2010 215  #define ESC_ERASE_DISPLAY ANSI_ESCAPE_SEQUENCE("2J")  Dean Camera committed May 08, 2010 216 217  /** Erases the current line, returning the cursor to the far left. */  Dean Camera committed Nov 17, 2010 218  #define ESC_ERASE_LINE ANSI_ESCAPE_SEQUENCE("K")  Dean Camera committed Oct 28, 2010 219  //@}  Dean Camera committed May 08, 2010 220 221 222 223  #endif /** @} */  224