Statistics
| Branch: | Tag: | Revision:

root / LUFA / Drivers / Misc / TerminalCodes.h @ 978b99e5

History | View | Annotate | Download (9.37 KB)

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
 *  \brief ANSI terminal special escape code macros.
41
 *
42
 *  \section Sec_Dependencies Module Source Dependencies
43
 *  The following files must be built with any user project that uses this module:
44
 *    - None
45
 *
46
 *  \section Sec_ModDescription Module Description
47
 *  Escape code macros for ANSI compliant text terminals.
48
 *
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).
52
 *
53
 *  \section Sec_ExampleUsage Example Usage
54
 *  The following snippet is an example of how this module may be used within a typical
55
 *  application.
56
 *
57
 *  \code
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");
62
 *  \endcode
63
 *
64
 *  @{
65
 */
66

    
67
#ifndef __TERMINALCODES_H__
68
#define __TERMINALCODES_H__
69

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

    
82
                        /** \name Text Display Modifier Escape Sequences */
83
                        //@{
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")
86

    
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")
89

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

    
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")
95

    
96
                        /** Turns on strikethrough so that any following text is printed to the terminal with a line through the
97
                         *  center.
98
                         */
99
                        #define ESC_STRIKETHROUGH_ON            ANSI_ESCAPE_SEQUENCE("9m")
100

    
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")
103

    
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")
106

    
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")
109

    
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")
112

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

    
124
                        /** Sets the foreground (text) colour to red. */
125
                        #define ESC_FG_RED                      ANSI_ESCAPE_SEQUENCE("31m")
126

    
127
                        /** Sets the foreground (text) colour to green. */
128
                        #define ESC_FG_GREEN                    ANSI_ESCAPE_SEQUENCE("32m")
129

    
130
                        /** Sets the foreground (text) colour to yellow. */
131
                        #define ESC_FG_YELLOW                   ANSI_ESCAPE_SEQUENCE("33m")
132

    
133
                        /** Sets the foreground (text) colour to blue. */
134
                        #define ESC_FG_BLUE                     ANSI_ESCAPE_SEQUENCE("34m")
135

    
136
                        /** Sets the foreground (text) colour to magenta. */
137
                        #define ESC_FG_MAGENTA                  ANSI_ESCAPE_SEQUENCE("35m")
138

    
139
                        /** Sets the foreground (text) colour to cyan. */
140
                        #define ESC_FG_CYAN                     ANSI_ESCAPE_SEQUENCE("36m")
141

    
142
                        /** Sets the foreground (text) colour to white. */
143
                        #define ESC_FG_WHITE                    ANSI_ESCAPE_SEQUENCE("37m")
144

    
145
                        /** Sets the foreground (text) colour to the terminal's default. */
146
                        #define ESC_FG_DEFAULT                  ANSI_ESCAPE_SEQUENCE("39m")
147

    
148
                        /** Sets the text background colour to black. */
149
                        #define ESC_BG_BLACK                    ANSI_ESCAPE_SEQUENCE("40m")
150

    
151
                        /** Sets the text background colour to red. */
152
                        #define ESC_BG_RED                      ANSI_ESCAPE_SEQUENCE("41m")
153

    
154
                        /** Sets the text background colour to green. */
155
                        #define ESC_BG_GREEN                    ANSI_ESCAPE_SEQUENCE("42m")
156

    
157
                        /** Sets the text background colour to yellow. */
158
                        #define ESC_BG_YELLOW                   ANSI_ESCAPE_SEQUENCE("43m")
159

    
160
                        /** Sets the text background colour to blue. */
161
                        #define ESC_BG_BLUE                     ANSI_ESCAPE_SEQUENCE("44m")
162

    
163
                        /** Sets the text background colour to magenta. */
164
                        #define ESC_BG_MAGENTA                  ANSI_ESCAPE_SEQUENCE("45m")
165

    
166
                        /** Sets the text background colour to cyan. */
167
                        #define ESC_BG_CYAN                     ANSI_ESCAPE_SEQUENCE("46m")
168

    
169
                        /** Sets the text background colour to white. */
170
                        #define ESC_BG_WHITE                    ANSI_ESCAPE_SEQUENCE("47m")
171

    
172
                        /** Sets the text background colour to the terminal's default. */
173
                        #define ESC_BG_DEFAULT                  ANSI_ESCAPE_SEQUENCE("49m")
174
                        //@}
175

    
176
                        /** \name Cursor Positioning Control Sequences */
177
                        //@{
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")
180

    
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")
183

    
184
                        /** Sets the cursor position to the given line and column.
185
                         *
186
                         *  \param[in] Line    Line number to position the cursor at.
187
                         *  \param[in] Column  Column number to position the cursor at.
188
                         */
189
                        #define ESC_CURSOR_POS(Line, Column)    ANSI_ESCAPE_SEQUENCE(#Line ";" #Column "H")
190

    
191
                        /** Moves the cursor up the given number of lines.
192
                         *
193
                         *  \param[in] Lines  Number of lines to move the cursor position
194
                         */
195
                        #define ESC_CURSOR_UP(Lines)            ANSI_ESCAPE_SEQUENCE(#Lines "A")
196

    
197
                        /** Moves the cursor down the given number of lines.
198
                         *
199
                         *  \param[in] Lines  Number of lines to move the cursor position
200
                         */
201
                        #define ESC_CURSOR_DOWN(Lines)          ANSI_ESCAPE_SEQUENCE(#Lines "B")
202

    
203
                        /** Moves the cursor to the right the given number of columns.
204
                         *
205
                         *  \param[in] Columns  Number of columns to move the cursor position
206
                         */
207
                        #define ESC_CURSOR_FORWARD(Columns)     ANSI_ESCAPE_SEQUENCE(#Columns "C")
208

    
209
                        /** Moves the cursor to the left the given number of columns.
210
                         *
211
                         *  \param[in] Columns  Number of columns to move the cursor position
212
                         */
213
                        #define ESC_CURSOR_BACKWARD(Columns)    ANSI_ESCAPE_SEQUENCE(#Columns "D")
214
                        //@}
215

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

    
221
                        /** Erases the entire display, returning the cursor to the top left. */
222
                        #define ESC_ERASE_DISPLAY               ANSI_ESCAPE_SEQUENCE("2J")
223

    
224
                        /** Erases the current line, returning the cursor to the far left. */
225
                        #define ESC_ERASE_LINE                  ANSI_ESCAPE_SEQUENCE("K")
226
                        //@}
227

    
228
#endif
229

    
230
/** @} */
231