Inspired by Simon Ford's "Terminal" library, this is a clean-room reimplementation that supports a larger set of the ANSI escape sequences and includes a few handy drawing routines. Useful for making console UIs for your projects. The box-drawing stuff requires your terminal to be set to codepage 850.
Fork of ANSITerm by
ANSITerm.h@2:a681bda60db7, 2013-02-28 (annotated)
- Committer:
- mbedDevLondon
- Date:
- Thu Feb 28 00:38:13 2013 +0000
- Revision:
- 2:a681bda60db7
- Parent:
- 1:e3403c93f864
no changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dansummers | 0:863811463610 | 1 | /** |
dansummers | 0:863811463610 | 2 | * @file ANSITerm.h |
dansummers | 0:863811463610 | 3 | * @author Dan Summers [ https://mbed.org/users/dansummers ] |
dansummers | 0:863811463610 | 4 | * @date 20120918 |
dansummers | 0:863811463610 | 5 | */ |
dansummers | 0:863811463610 | 6 | /* |
dansummers | 0:863811463610 | 7 | Copyright (c) 2012 dansummers |
dansummers | 0:863811463610 | 8 | |
dansummers | 0:863811463610 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
dansummers | 0:863811463610 | 10 | this software and associated documentation files (the "Software"), to deal in |
dansummers | 0:863811463610 | 11 | the Software without restriction, including without limitation the rights to |
dansummers | 0:863811463610 | 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
dansummers | 0:863811463610 | 13 | of the Software, and to permit persons to whom the Software is furnished to do |
dansummers | 0:863811463610 | 14 | so, subject to the following conditions: |
dansummers | 0:863811463610 | 15 | |
dansummers | 0:863811463610 | 16 | The above copyright notice and this permission notice shall be included in all |
dansummers | 0:863811463610 | 17 | copies or substantial portions of the Software. |
dansummers | 0:863811463610 | 18 | |
dansummers | 0:863811463610 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dansummers | 0:863811463610 | 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dansummers | 0:863811463610 | 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dansummers | 0:863811463610 | 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dansummers | 0:863811463610 | 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dansummers | 0:863811463610 | 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
dansummers | 0:863811463610 | 25 | SOFTWARE. |
dansummers | 0:863811463610 | 26 | */ |
dansummers | 0:863811463610 | 27 | |
dansummers | 0:863811463610 | 28 | #ifndef _ANSITERM_ |
dansummers | 0:863811463610 | 29 | #define _ANSITERM_ |
dansummers | 0:863811463610 | 30 | |
dansummers | 0:863811463610 | 31 | #define _ANSITERM_CP850_ /* Use CodePage 850 for box-drawing. */ |
dansummers | 0:863811463610 | 32 | |
dansummers | 0:863811463610 | 33 | #include "mbed.h" |
dansummers | 0:863811463610 | 34 | |
dansummers | 0:863811463610 | 35 | /** ANSI Terminal control library, inheriting from Serial. |
dansummers | 0:863811463610 | 36 | * |
dansummers | 0:863811463610 | 37 | * ANSITerm encapsulates a large portion of the ANSI escape sequence set, |
dansummers | 0:863811463610 | 38 | * so that a user unfamiliar with the escape sequences can manipulate the |
dansummers | 0:863811463610 | 39 | * terminal. It also provides a tidy point of abstraction, should it be |
dansummers | 0:863811463610 | 40 | * necessary to support multiple different escape sets in the future. |
dansummers | 0:863811463610 | 41 | * |
dansummers | 0:863811463610 | 42 | * ANSITerm assumes that the terminal being manipulated implements the |
dansummers | 0:863811463610 | 43 | * ANSI-standard escapes. The terminal is divided into cells, each one |
dansummers | 0:863811463610 | 44 | * the size of a character (a typical "default" terminal will have 25 rows of |
dansummers | 0:863811463610 | 45 | * cells, each with 80 character cells in it, but this will change if the |
dansummers | 0:863811463610 | 46 | * terminal is resized.) |
dansummers | 0:863811463610 | 47 | * |
dansummers | 0:863811463610 | 48 | * The box-drawing functions currently assume that the terminal is using |
dansummers | 0:863811463610 | 49 | * CodePage 850 to interpret received characters. It is untested under |
dansummers | 0:863811463610 | 50 | * UNIX and MacOS (fixing this is on the TODO list). |
dansummers | 0:863811463610 | 51 | * |
dansummers | 0:863811463610 | 52 | * Example: |
dansummers | 0:863811463610 | 53 | * @code |
dansummers | 0:863811463610 | 54 | * terminal.clear_screen(); |
dansummers | 0:863811463610 | 55 | * terminal.hide_cursor(); |
dansummers | 0:863811463610 | 56 | * terminal.set_display_style(ANSITerm::SGR_NONE); |
dansummers | 0:863811463610 | 57 | * terminal.set_text_colour(ANSITerm::SGR_RED); |
dansummers | 0:863811463610 | 58 | * terminal.draw_box(3,3,19,5,ANSITerm::simple,false); |
dansummers | 0:863811463610 | 59 | * terminal.set_text_colour(ANSITerm::SGR_WHITE); |
dansummers | 0:863811463610 | 60 | * terminal.set_display_style(ANSITerm::SGR_BOLD); |
dansummers | 0:863811463610 | 61 | * terminal.set_cursor_position(5,4); |
dansummers | 0:863811463610 | 62 | * terminal.printf("ANSI Terminal"); |
dansummers | 0:863811463610 | 63 | * @endcode |
dansummers | 0:863811463610 | 64 | */ |
dansummers | 0:863811463610 | 65 | class ANSITerm : public Serial |
dansummers | 0:863811463610 | 66 | { |
dansummers | 0:863811463610 | 67 | public: |
dansummers | 0:863811463610 | 68 | /* Internal buffer for the SGR style flagset currently in use. */ |
dansummers | 0:863811463610 | 69 | char current_style; |
dansummers | 0:863811463610 | 70 | |
dansummers | 0:863811463610 | 71 | /** SGR "flag" indicating the default text style. */ |
dansummers | 0:863811463610 | 72 | const static char SGR_NONE = 0; |
dansummers | 0:863811463610 | 73 | |
dansummers | 0:863811463610 | 74 | /** SGR flag to request bold text. */ |
dansummers | 0:863811463610 | 75 | const static char SGR_BOLD = 1; |
dansummers | 0:863811463610 | 76 | |
dansummers | 0:863811463610 | 77 | /** SGR flag to request faint text. */ |
dansummers | 0:863811463610 | 78 | const static char SGR_FAINT = 2; |
dansummers | 0:863811463610 | 79 | |
dansummers | 0:863811463610 | 80 | /** SGR flag to request italic text. */ |
dansummers | 0:863811463610 | 81 | const static char SGR_ITALIC = 4; |
dansummers | 0:863811463610 | 82 | |
dansummers | 0:863811463610 | 83 | /** SGR flag to request underlined text. */ |
dansummers | 0:863811463610 | 84 | const static char SGR_UNDERLINE = 8; |
dansummers | 0:863811463610 | 85 | |
dansummers | 0:863811463610 | 86 | /** SGR flag to request slow-blinking text (not always supported). */ |
dansummers | 0:863811463610 | 87 | const static char SGR_BLINK_SLOW = 16; |
dansummers | 0:863811463610 | 88 | |
dansummers | 0:863811463610 | 89 | /** SGR flag to request fast-flashing text (not always supported). */ |
dansummers | 0:863811463610 | 90 | const static char SGR_BLINK_RAPID = 32; |
dansummers | 0:863811463610 | 91 | |
dansummers | 0:863811463610 | 92 | /** SGR flag to request inverse-video. */ |
dansummers | 0:863811463610 | 93 | const static char SGR_IMAGE_NEGATIVE = 64; /* Switch on inverse video */ |
dansummers | 0:863811463610 | 94 | |
dansummers | 0:863811463610 | 95 | /** SGR flag to request struck-through text (not commonly supported).*/ |
dansummers | 0:863811463610 | 96 | const static char SGR_CROSSED_OUT = 128; |
dansummers | 0:863811463610 | 97 | |
dansummers | 0:863811463610 | 98 | /* SGR colours */ |
dansummers | 0:863811463610 | 99 | /** SGR colour indicator for ANSI Black.*/ |
dansummers | 0:863811463610 | 100 | const static char SGR_BLACK = 1; //30 |
dansummers | 0:863811463610 | 101 | |
dansummers | 0:863811463610 | 102 | /** SGR colour indicator for ANSI Red.*/ |
dansummers | 0:863811463610 | 103 | const static char SGR_RED = 2; //31 |
dansummers | 0:863811463610 | 104 | |
dansummers | 0:863811463610 | 105 | /** SGR colour indicator for ANSI Green.*/ |
dansummers | 0:863811463610 | 106 | const static char SGR_GREEN = 4; //32 |
dansummers | 0:863811463610 | 107 | |
dansummers | 0:863811463610 | 108 | /** SGR colour indicator for ANSI Yellow.*/ |
dansummers | 0:863811463610 | 109 | const static char SGR_YELLOW = 8; //33 |
dansummers | 0:863811463610 | 110 | |
dansummers | 0:863811463610 | 111 | /** SGR colour indicator for ANSI Blue.*/ |
dansummers | 0:863811463610 | 112 | const static char SGR_BLUE = 16; //34 |
dansummers | 0:863811463610 | 113 | |
dansummers | 0:863811463610 | 114 | /** SGR colour indicator for ANSI Magenta.*/ |
dansummers | 0:863811463610 | 115 | const static char SGR_MAGENTA = 32; //35 |
dansummers | 0:863811463610 | 116 | |
dansummers | 0:863811463610 | 117 | /** SGR colour indicator for ANSI Cyan.*/ |
dansummers | 0:863811463610 | 118 | const static char SGR_CYAN = 64; //36 |
dansummers | 0:863811463610 | 119 | |
dansummers | 0:863811463610 | 120 | /** SGR colour indicator for ANSI White.*/ |
dansummers | 0:863811463610 | 121 | const static char SGR_WHITE = 128; //37 |
dansummers | 0:863811463610 | 122 | |
dansummers | 0:863811463610 | 123 | /* Box styles */ |
dansummers | 1:e3403c93f864 | 124 | const static char BOXDRAW_TOPLEFT = 0; |
dansummers | 1:e3403c93f864 | 125 | const static char BOXDRAW_TOPRIGHT = 1; |
dansummers | 1:e3403c93f864 | 126 | const static char BOXDRAW_BOTTOMLEFT = 2; |
dansummers | 1:e3403c93f864 | 127 | const static char BOXDRAW_BOTTOMRIGHT = 3; |
dansummers | 1:e3403c93f864 | 128 | const static char BOXDRAW_HORIZONTAL = 4; |
dansummers | 1:e3403c93f864 | 129 | const static char BOXDRAW_VERTICAL = 5; |
dansummers | 1:e3403c93f864 | 130 | const static char BOXDRAW_UPTEE = 6; |
dansummers | 1:e3403c93f864 | 131 | const static char BOXDRAW_DOWNTEE = 7; |
dansummers | 1:e3403c93f864 | 132 | const static char BOXDRAW_LEFTTEE = 8; |
dansummers | 1:e3403c93f864 | 133 | const static char BOXDRAW_RIGHTTEE = 9; |
dansummers | 1:e3403c93f864 | 134 | const static char BOXDRAW_CROSS = 10; |
dansummers | 0:863811463610 | 135 | #ifdef _ANSITERM_CP850_ |
dansummers | 1:e3403c93f864 | 136 | /** Box-drawing style using pluses, minuses and pipes (low-ASCII, should work anywhere).*/ |
dansummers | 1:e3403c93f864 | 137 | static const char simple[11]; |
dansummers | 1:e3403c93f864 | 138 | |
dansummers | 0:863811463610 | 139 | /** Box-drawing style using ASCII two-line box-drawing characters. */ |
dansummers | 0:863811463610 | 140 | static const char two_lines[11]; |
dansummers | 0:863811463610 | 141 | |
dansummers | 0:863811463610 | 142 | /** Box-drawing style using ASCII one-line box-drawing characters. */ |
dansummers | 0:863811463610 | 143 | static const char one_line[11]; |
dansummers | 0:863811463610 | 144 | #endif |
dansummers | 0:863811463610 | 145 | |
dansummers | 0:863811463610 | 146 | ANSITerm(PinName tx, PinName rx); |
dansummers | 0:863811463610 | 147 | |
dansummers | 0:863811463610 | 148 | /* Emit a Control Sequence Initiator (which is the header for an ANSI escape sequence). */ |
dansummers | 0:863811463610 | 149 | inline void ansi_csi() { this->putc(0x1B); this->putc('['); } |
dansummers | 0:863811463610 | 150 | /* Cursor Up by n rows. */ |
dansummers | 0:863811463610 | 151 | inline void ansi_cuu(int n) { this->printf("%dA", n); } |
dansummers | 0:863811463610 | 152 | /* Cursor Down by n rows. */ |
dansummers | 0:863811463610 | 153 | inline void ansi_cud(int n) { this->printf("%dB", n); } |
dansummers | 0:863811463610 | 154 | /* Cursor Forward by n columns. */ |
dansummers | 0:863811463610 | 155 | inline void ansi_cuf(int n) { this->printf("%dC", n); } |
dansummers | 0:863811463610 | 156 | /* Cursor Back by n columns. */ |
dansummers | 0:863811463610 | 157 | inline void ansi_cub(int n) { this->printf("%dD", n); } |
dansummers | 0:863811463610 | 158 | /* Cursor Next Line (moves the cursor to the start of the line n lines down). */ |
dansummers | 0:863811463610 | 159 | inline void ansi_cnl(int n) { this->printf("%dE", n); } |
dansummers | 0:863811463610 | 160 | /* Cursor Previous Line (moves the cursor to the start of the line n lines up). */ |
dansummers | 0:863811463610 | 161 | inline void ansi_cpl(int n) { this->printf("%dF", n); } |
dansummers | 0:863811463610 | 162 | /* Cursor Horizontal Absolute (moves the cursor to column n). */ |
dansummers | 0:863811463610 | 163 | inline void ansi_cha(int n) { this->printf("%dG", n); } |
dansummers | 0:863811463610 | 164 | /* Cursor Position (positions the cursor at column x, row y, on a 1-based grid starting top-left). */ |
dansummers | 0:863811463610 | 165 | inline void ansi_cup(int x, int y) { this->printf("%d;%dH", y, x); } |
dansummers | 0:863811463610 | 166 | /* Erase Data (0 = from cursor to end of screen, 1 = from cursor to beginning of screen, 2 = entire screen) */ |
dansummers | 0:863811463610 | 167 | inline void ansi_ed(int n) { this->printf("%dJ", n); } |
dansummers | 0:863811463610 | 168 | /* Erase in Line (0 = from cursor to end of screen, 1 = from cursor to beginning of screen, 2 = entire screen) */ |
dansummers | 0:863811463610 | 169 | inline void ansi_el(int n) { this->printf("%dK", n); } |
dansummers | 0:863811463610 | 170 | /* Scroll Up by n lines. */ |
dansummers | 0:863811463610 | 171 | inline void ansi_su(int n) { this->printf("%dS", n); } |
dansummers | 0:863811463610 | 172 | /* Scroll Down by n lines. */ |
dansummers | 0:863811463610 | 173 | inline void ansi_sd(int n) { this->printf("%dT", n); } |
dansummers | 0:863811463610 | 174 | /* Horizontal and Vertical Position (positions the cursor at column x, row y, on a 1-based grid starting top-left). */ |
dansummers | 0:863811463610 | 175 | inline void ansi_hvp(int y, int x) { this->printf("%d;%dH", y, x); } |
dansummers | 0:863811463610 | 176 | /* Save Cursor Position */ |
dansummers | 0:863811463610 | 177 | inline void ansi_scp() { this->putc('s'); } |
dansummers | 0:863811463610 | 178 | /* Restore Cursor Position */ |
dansummers | 0:863811463610 | 179 | inline void ansi_rcp() { this->putc('u'); } |
dansummers | 0:863811463610 | 180 | /*DEC Terminal Cursor Enable Mode - hide cursor */ |
dansummers | 0:863811463610 | 181 | inline void ansi_dectcem_hide() { this->printf("?25l"); } |
dansummers | 0:863811463610 | 182 | /*DEC Terminal Cursor Enable Mode - show cursor */ |
dansummers | 0:863811463610 | 183 | inline void ansi_dectcem_show() { this->printf("?25h"); } |
dansummers | 0:863811463610 | 184 | |
dansummers | 0:863811463610 | 185 | /* Select Graphic Rendition - Make the output bold, underlined, coloured... all manner of things.*/ |
dansummers | 0:863811463610 | 186 | /* |
dansummers | 0:863811463610 | 187 | reset = 1 to reset to defaults. 0 to read and apply the rest of the inputs. |
dansummers | 0:863811463610 | 188 | text_style is an OR of SGR_{BOLD,FAINT,ITALIC,UNDERLINE,BLINK_SLOW,BLINK_RAPID,IMAGE_NEGATIVE,CROSSED_OUT} |
dansummers | 0:863811463610 | 189 | text_colour is one of SGR_{BLACK,RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE} |
dansummers | 0:863811463610 | 190 | background_colour is one of SGR_{BLACK,RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE} |
dansummers | 0:863811463610 | 191 | */ |
dansummers | 0:863811463610 | 192 | void ansi_sgr(bool reset, char text_style, char text_colour, char background_colour); |
dansummers | 0:863811463610 | 193 | |
dansummers | 0:863811463610 | 194 | /* Device Status Report (Returns CSIn;mR, where n,m is the coordinates of the cursor). */ |
dansummers | 0:863811463610 | 195 | void ansi_dsr(int* x_coord, int* y_coord); |
dansummers | 0:863811463610 | 196 | |
dansummers | 0:863811463610 | 197 | /** Position the cursor at the requested coordinates, relative to the terminal frame. |
dansummers | 0:863811463610 | 198 | * Coordinates are calculated from the top left of the frame, using character |
dansummers | 0:863811463610 | 199 | * cells as the unit, and start at an origin of (1,1). |
dansummers | 0:863811463610 | 200 | * @param x_coord the x-coordinate (column number) in which to place the cursor, starting at 1. |
dansummers | 0:863811463610 | 201 | * @param y_coord the y coordinate (row number) in which to place the cursor, starting at 1. |
dansummers | 0:863811463610 | 202 | */ |
dansummers | 0:863811463610 | 203 | inline void set_cursor_position(int x_coord, int y_coord) |
dansummers | 0:863811463610 | 204 | { |
dansummers | 0:863811463610 | 205 | this->ansi_csi(); |
dansummers | 0:863811463610 | 206 | this->ansi_cup(x_coord, y_coord); |
dansummers | 0:863811463610 | 207 | } |
dansummers | 0:863811463610 | 208 | |
dansummers | 0:863811463610 | 209 | /** Get the current position of the cursor, relative to the terminal frame. |
dansummers | 0:863811463610 | 210 | * Coordinates are calculated from the top left of the frame, using character |
dansummers | 0:863811463610 | 211 | * cells as the unit, and start at an origin of (1,1). |
dansummers | 0:863811463610 | 212 | * @param x_coord A pointer into which the current x-coordinate of the cursor should be written. |
dansummers | 0:863811463610 | 213 | * @param y_coord A pointer into which the current y-coordinate of the cursor should be written. |
dansummers | 0:863811463610 | 214 | */ |
dansummers | 0:863811463610 | 215 | inline void get_cursor_position(int* x_coord, int* y_coord) |
dansummers | 0:863811463610 | 216 | { |
dansummers | 0:863811463610 | 217 | this->ansi_csi(); |
dansummers | 0:863811463610 | 218 | this->ansi_dsr(x_coord, y_coord); |
dansummers | 0:863811463610 | 219 | } |
dansummers | 0:863811463610 | 220 | |
dansummers | 0:863811463610 | 221 | /** Blank all cells on the screen. |
dansummers | 0:863811463610 | 222 | */ |
dansummers | 0:863811463610 | 223 | inline void clear_screen() |
dansummers | 0:863811463610 | 224 | { |
dansummers | 0:863811463610 | 225 | this->ansi_csi(); |
dansummers | 0:863811463610 | 226 | this->ansi_ed(2); |
dansummers | 0:863811463610 | 227 | } |
dansummers | 0:863811463610 | 228 | |
dansummers | 0:863811463610 | 229 | /** Draw a box with these top-left and bottom-right points. Various styling options exist. |
dansummers | 0:863811463610 | 230 | * @param x1 The x-coordinate of the top-left point. |
dansummers | 0:863811463610 | 231 | * @param y1 The y-coordinate of the top-left point. |
dansummers | 0:863811463610 | 232 | * @param x2 The x-coordinate of the bottom-right point. |
dansummers | 0:863811463610 | 233 | * @param style The style of box-drawing to use (an 11-cell array of glyphs to use: three sets are defined above). |
dansummers | 0:863811463610 | 234 | * The styles are stored as arrays of eleven glyphs, with the following descriptive names: |
dansummers | 0:863811463610 | 235 | * [0]top-left corner, [1]top-right corner, [2]bottom-left corner, [3]bottom-right corner, |
dansummers | 0:863811463610 | 236 | * [4]horizontal bar, [5]vertical bar, |
dansummers | 0:863811463610 | 237 | * [6]upward-pointing tee, [7]downward-pointing tee, [8]left-pointing tee, [9]right-pointing tee, |
dansummers | 0:863811463610 | 238 | * [10]cross |
dansummers | 0:863811463610 | 239 | * @param clear_inner If true, the space contained within the box will be overwritten with space characters. If not, it will be unmodified. |
dansummers | 0:863811463610 | 240 | */ |
dansummers | 0:863811463610 | 241 | void draw_box(int x1, int y1, int x2, int y2, const char* style, bool clear_inner); |
dansummers | 0:863811463610 | 242 | |
dansummers | 0:863811463610 | 243 | /** Draw a box containing these top-left and bottom-right points. Various styling options exist. |
dansummers | 0:863811463610 | 244 | * @param x1 The x-coordinate of the top-left point. |
dansummers | 0:863811463610 | 245 | * @param y1 The y-coordinate of the top-left point. |
dansummers | 0:863811463610 | 246 | * @param x2 The x-coordinate of the bottom-right point. |
dansummers | 0:863811463610 | 247 | * @param style The style of box-drawing to use (an 11-cell array of glyphs to use: three sets are defined above). |
dansummers | 0:863811463610 | 248 | * The styles are stored as arrays of eleven glyphs, with the following descriptive names: |
dansummers | 0:863811463610 | 249 | * [0]top-left corner, [1]top-right corner, [2]bottom-left corner, [3]bottom-right corner, |
dansummers | 0:863811463610 | 250 | * [4]horizontal bar, [5]vertical bar, |
dansummers | 0:863811463610 | 251 | * [6]upward-pointing tee, [7]downward-pointing tee, [8]left-pointing tee, [9]right-pointing tee, |
dansummers | 0:863811463610 | 252 | * [10]cross |
dansummers | 0:863811463610 | 253 | * @param clear_inner If true, the space contained within the box will be overwritten with space characters. If not, it will be unmodified. |
dansummers | 0:863811463610 | 254 | * |
dansummers | 0:863811463610 | 255 | * draw_enclosing_box differs from draw_box because it draws around a space |
dansummers | 0:863811463610 | 256 | * rather than inscribing it. If draw_box and draw_enclosing_box are given |
dansummers | 0:863811463610 | 257 | * the same parameters, they will draw concentric boxes and the box from |
dansummers | 0:863811463610 | 258 | * draw_box will be two cells smaller in both dimensions. |
dansummers | 0:863811463610 | 259 | */ |
dansummers | 0:863811463610 | 260 | inline void draw_enclosing_box(int x1, int y1, int x2, int y2, const char* style, bool clear_inner) |
dansummers | 0:863811463610 | 261 | { |
dansummers | 0:863811463610 | 262 | draw_box((x1-1), (y1-1), (x2+1), (y2+1), style, clear_inner); |
dansummers | 0:863811463610 | 263 | } |
dansummers | 0:863811463610 | 264 | |
dansummers | 0:863811463610 | 265 | /** Set the SGR display style for subsequent characters. |
dansummers | 0:863811463610 | 266 | * @param style A flagset ORred together from the SGR parameters above. |
dansummers | 0:863811463610 | 267 | * Flags that are set in the flagset will be turned on, |
dansummers | 0:863811463610 | 268 | * flags that are clear will be turned off. |
dansummers | 0:863811463610 | 269 | * |
dansummers | 0:863811463610 | 270 | * Example: |
dansummers | 0:863811463610 | 271 | * @code |
dansummers | 0:863811463610 | 272 | * terminal.printf("Some text."); |
dansummers | 0:863811463610 | 273 | * terminal.set_display_style(SGR_BOLD|SGR_UNDERLINE); |
dansummers | 0:863811463610 | 274 | * terminal.printf("Some very important text!"); |
dansummers | 0:863811463610 | 275 | * terminal.set_display_style(SGR_NONE); |
dansummers | 0:863811463610 | 276 | * terminal.printf("Some more normal text."); |
dansummers | 0:863811463610 | 277 | * @endcode |
dansummers | 0:863811463610 | 278 | */ |
dansummers | 0:863811463610 | 279 | inline void set_display_style(char style) |
dansummers | 0:863811463610 | 280 | { |
dansummers | 0:863811463610 | 281 | this->current_style = style; |
dansummers | 0:863811463610 | 282 | this->ansi_csi(); |
dansummers | 0:863811463610 | 283 | this->ansi_sgr(false, style, 0, 0); |
dansummers | 0:863811463610 | 284 | } |
dansummers | 0:863811463610 | 285 | |
dansummers | 0:863811463610 | 286 | /** Set the colour of subsequent characters. |
dansummers | 0:863811463610 | 287 | * @param sgr_colour One of the SGR Colours defined above (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White). |
dansummers | 0:863811463610 | 288 | * |
dansummers | 0:863811463610 | 289 | * Example: |
dansummers | 0:863811463610 | 290 | * @code |
dansummers | 0:863811463610 | 291 | * terminal.printf("Some text in the default terminal colour."); |
dansummers | 0:863811463610 | 292 | * terminal.set_display_text_colour(SGR_RED); |
dansummers | 0:863811463610 | 293 | * terminal.printf("Some text in red.); |
dansummers | 0:863811463610 | 294 | * @endcode |
dansummers | 0:863811463610 | 295 | */ |
dansummers | 0:863811463610 | 296 | inline void set_text_colour(char sgr_colour) |
dansummers | 0:863811463610 | 297 | { |
dansummers | 0:863811463610 | 298 | this->ansi_csi(); |
dansummers | 0:863811463610 | 299 | this->ansi_sgr(false, this->current_style, sgr_colour, 0); |
dansummers | 0:863811463610 | 300 | } |
dansummers | 0:863811463610 | 301 | |
dansummers | 0:863811463610 | 302 | /** Set the background colour for subsequent characters. |
dansummers | 0:863811463610 | 303 | * @param sgr_colour One of the SGR Colours defined above (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White). |
dansummers | 0:863811463610 | 304 | * |
dansummers | 0:863811463610 | 305 | * Example: |
dansummers | 0:863811463610 | 306 | * @code |
dansummers | 0:863811463610 | 307 | * terminal.printf("Some text in the default terminal colour."); |
dansummers | 0:863811463610 | 308 | * terminal.set_display_background_colour(SGR_RED); |
dansummers | 0:863811463610 | 309 | * terminal.printf("Some text on a red background.); |
dansummers | 0:863811463610 | 310 | * @endcode |
dansummers | 0:863811463610 | 311 | */ |
dansummers | 0:863811463610 | 312 | inline void set_background_colour(char sgr_colour) |
dansummers | 0:863811463610 | 313 | { |
dansummers | 0:863811463610 | 314 | this->ansi_csi(); |
dansummers | 0:863811463610 | 315 | this->ansi_sgr(false, this->current_style, 0, sgr_colour); |
dansummers | 0:863811463610 | 316 | } |
dansummers | 0:863811463610 | 317 | |
dansummers | 0:863811463610 | 318 | /** Tell the terminal not to display the cursor. |
dansummers | 0:863811463610 | 319 | */ |
dansummers | 0:863811463610 | 320 | inline void hide_cursor() |
dansummers | 0:863811463610 | 321 | { |
dansummers | 0:863811463610 | 322 | this->ansi_csi(); |
dansummers | 0:863811463610 | 323 | this->ansi_dectcem_hide(); |
dansummers | 0:863811463610 | 324 | } |
dansummers | 0:863811463610 | 325 | |
dansummers | 0:863811463610 | 326 | /** Tell the terminal to display the cursor. |
dansummers | 0:863811463610 | 327 | */ |
dansummers | 0:863811463610 | 328 | inline void show_cursor() |
dansummers | 0:863811463610 | 329 | { |
dansummers | 0:863811463610 | 330 | this->ansi_csi(); |
dansummers | 0:863811463610 | 331 | this->ansi_dectcem_show(); |
dansummers | 0:863811463610 | 332 | } |
dansummers | 0:863811463610 | 333 | |
dansummers | 0:863811463610 | 334 | /** Reset the display to its default parameters (clearing all text styling and colour settings). |
dansummers | 0:863811463610 | 335 | */ |
dansummers | 0:863811463610 | 336 | inline void set_display_to_defaults() |
dansummers | 0:863811463610 | 337 | { |
dansummers | 0:863811463610 | 338 | this->ansi_csi(); |
dansummers | 0:863811463610 | 339 | this->ansi_sgr(true, 0, 0, 0); |
dansummers | 0:863811463610 | 340 | } |
dansummers | 0:863811463610 | 341 | |
dansummers | 0:863811463610 | 342 | }; |
dansummers | 0:863811463610 | 343 | |
dansummers | 0:863811463610 | 344 | |
dansummers | 0:863811463610 | 345 | #endif |