My implementation of VT100 ESC-sequence utility
Dependents: test_vt100 maze_vt100_MMA8451Q funcgen test_MAG3110 ... more
vt100.h
00001 #ifndef VT100_H 00002 #define VT100_H included 00003 00004 /** vt100 class 00005 * Utility for handling text/letter on a terminal 00006 * which can handle VT100 escape command sequence. 00007 * 00008 * Example: 00009 * @code 00010 * #include "mbed.h" 00011 * #include "vt100.h" 00012 * 00013 * vt100 tty ; 00014 * 00015 * int main() { 00016 * int count = 0 ; 00017 * tty.cls() ; 00018 * tty.black() ; 00019 * tty.frame(5, 5, 15, 9) ; 00020 * while(1) { 00021 * tty.locate(7, 7) ; 00022 * tty.setFG(count % 8) ; 00023 * printf("%d\r\n", count++) ; 00024 * wait(1.0) ; 00025 * } 00026 * } 00027 * @endcode 00028 * 00029 * Note: I know there should be other libraries 00030 * with similar functions, but I could not help 00031 * writing one for myself anyway. 00032 */ 00033 00034 class vt100 { 00035 public: 00036 /** constructor 00037 * @param baud baud rate 00038 */ 00039 vt100(int baud = 115200) ; 00040 00041 /** destructor */ 00042 ~vt100(void) ; 00043 00044 /** clear screen */ 00045 void cls(void) ; 00046 00047 /** move cursor to (x, y) 00048 * @param x start column of the next letter 00049 * @param y start row of the next letter 00050 * @note no value checking is performed. 00051 */ 00052 void locate(int x, int y) ; 00053 00054 /** print a letter c at (x,y) 00055 * @param c the letter to be written 00056 * @param x column of the letter 00057 * @param y row of the letter 00058 */ 00059 void putChar(int x, int y, char c) ; 00060 00061 /** print a string str from (x,y) 00062 * @param *str c-style string to be written 00063 * @param x column of the first letter 00064 * @param y row of the first letter 00065 */ 00066 void putStr(int x, int y, char *str) ; 00067 00068 /** print a line of char 00069 * @param c the letter to form the line 00070 * @param x1 starting column 00071 * @param y1 starting row 00072 * @param x2 ending column 00073 * @param y2 ending row 00074 */ 00075 void line(int x1, int y1, int x2, int y2, char c='*') ; 00076 00077 /** print a text frame 00078 * @param x1 left column 00079 * @param y1 top row 00080 * @param x2 right column 00081 * @param y2 bottom row 00082 */ 00083 void frame(int x1, int y1, int x2, int y2) ; 00084 00085 /** print a text circle 00086 * @c the letter to form the circle 00087 * @param x0 center column 00088 * @param y1 center row 00089 * @param r radius 00090 */ 00091 void circle(int x0, int y0, int r, char c='*') ; 00092 00093 /** set foreground color 00094 * @param newFG new foreground color 00095 * @returns previous foreground color 00096 * @note 0 BLACK 00097 * @note 1 RED 00098 * @note 2 GREEN 00099 * @note 3 YELLOW 00100 * @note 4 BLUE 00101 * @note 5 PURPLE 00102 * @note 6 CIAN 00103 * @note 7 WHITE 00104 */ 00105 int setFG(int newFG) ; 00106 00107 /** get current foreground color 00108 * @returns current foreground color 00109 */ 00110 int getFG(void) ; 00111 00112 /** set background color 00113 * @param newBG new background color 00114 * @returns previous background color 00115 */ 00116 int setBG(int newBG) ; 00117 00118 /** get current background color 00119 * @returns current background color 00120 */ 00121 int getBG(void) ; 00122 /** set foreground color to black */ 00123 void black(void) ; 00124 /** set foreground color to red */ 00125 void red(void) ; 00126 /** set foreground color to green */ 00127 void green(void) ; 00128 /** set foreground color to yellow */ 00129 void yellow(void) ; 00130 /** set foreground color to blue */ 00131 void blue(void) ; 00132 /** set foreground color to purple */ 00133 void purple(void) ; 00134 /** set foreground color to cian */ 00135 void cian(void) ; 00136 /** set foreground color to white */ 00137 void white(void) ; 00138 protected: 00139 private: 00140 int foreground ; 00141 int background ; 00142 00143 } ; 00144 00145 #endif /* VT100_H */
Generated on Fri Jul 15 2022 08:24:33 by 1.7.2