My implementation of VT100 ESC-sequence utility
Fork of vt100 by
vt100.h@2:0a86bf429b6f, 2015-06-16 (annotated)
- Committer:
- ftagius
- Date:
- Tue Jun 16 11:52:44 2015 +0000
- Revision:
- 2:0a86bf429b6f
- Parent:
- 0:94253645a02a
local version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:94253645a02a | 1 | #ifndef VT100_H |
Rhyme | 0:94253645a02a | 2 | #define VT100_H included |
Rhyme | 0:94253645a02a | 3 | |
Rhyme | 0:94253645a02a | 4 | /** vt100 class |
Rhyme | 0:94253645a02a | 5 | * Utility for handling text/letter on a terminal |
Rhyme | 0:94253645a02a | 6 | * which can handle VT100 escape command sequence. |
Rhyme | 0:94253645a02a | 7 | * |
Rhyme | 0:94253645a02a | 8 | * Example: |
Rhyme | 0:94253645a02a | 9 | * @code |
Rhyme | 0:94253645a02a | 10 | * #include "mbed.h" |
Rhyme | 0:94253645a02a | 11 | * #include "vt100.h" |
Rhyme | 0:94253645a02a | 12 | * |
Rhyme | 0:94253645a02a | 13 | * vt100 tty ; |
Rhyme | 0:94253645a02a | 14 | * |
Rhyme | 0:94253645a02a | 15 | * int main() { |
Rhyme | 0:94253645a02a | 16 | * int count = 0 ; |
Rhyme | 0:94253645a02a | 17 | * tty.cls() ; |
Rhyme | 0:94253645a02a | 18 | * tty.black() ; |
Rhyme | 0:94253645a02a | 19 | * tty.frame(5, 5, 15, 9) ; |
Rhyme | 0:94253645a02a | 20 | * while(1) { |
Rhyme | 0:94253645a02a | 21 | * tty.locate(7, 7) ; |
Rhyme | 0:94253645a02a | 22 | * tty.setFG(count % 8) ; |
Rhyme | 0:94253645a02a | 23 | * printf("%d\r\n", count++) ; |
Rhyme | 0:94253645a02a | 24 | * wait(1.0) ; |
Rhyme | 0:94253645a02a | 25 | * } |
Rhyme | 0:94253645a02a | 26 | * } |
Rhyme | 0:94253645a02a | 27 | * @endcode |
Rhyme | 0:94253645a02a | 28 | * |
Rhyme | 0:94253645a02a | 29 | * Note: I know there should be other libraries |
Rhyme | 0:94253645a02a | 30 | * with similar functions, but I could not help |
Rhyme | 0:94253645a02a | 31 | * writing one for myself anyway. |
Rhyme | 0:94253645a02a | 32 | */ |
Rhyme | 0:94253645a02a | 33 | |
Rhyme | 0:94253645a02a | 34 | class vt100 { |
Rhyme | 0:94253645a02a | 35 | public: |
Rhyme | 0:94253645a02a | 36 | /** constructor |
Rhyme | 0:94253645a02a | 37 | * @param baud baud rate |
Rhyme | 0:94253645a02a | 38 | */ |
ftagius | 2:0a86bf429b6f | 39 | vt100(int baud = 9600) ; |
Rhyme | 0:94253645a02a | 40 | |
Rhyme | 0:94253645a02a | 41 | /** destructor */ |
Rhyme | 0:94253645a02a | 42 | ~vt100(void) ; |
Rhyme | 0:94253645a02a | 43 | |
Rhyme | 0:94253645a02a | 44 | /** clear screen */ |
Rhyme | 0:94253645a02a | 45 | void cls(void) ; |
Rhyme | 0:94253645a02a | 46 | |
Rhyme | 0:94253645a02a | 47 | /** move cursor to (x, y) |
Rhyme | 0:94253645a02a | 48 | * @param x start column of the next letter |
Rhyme | 0:94253645a02a | 49 | * @param y start row of the next letter |
Rhyme | 0:94253645a02a | 50 | * @note no value checking is performed. |
Rhyme | 0:94253645a02a | 51 | */ |
Rhyme | 0:94253645a02a | 52 | void locate(int x, int y) ; |
Rhyme | 0:94253645a02a | 53 | |
Rhyme | 0:94253645a02a | 54 | /** print a letter c at (x,y) |
Rhyme | 0:94253645a02a | 55 | * @param c the letter to be written |
Rhyme | 0:94253645a02a | 56 | * @param x column of the letter |
Rhyme | 0:94253645a02a | 57 | * @param y row of the letter |
Rhyme | 0:94253645a02a | 58 | */ |
Rhyme | 0:94253645a02a | 59 | void putChar(int x, int y, char c) ; |
Rhyme | 0:94253645a02a | 60 | |
Rhyme | 0:94253645a02a | 61 | /** print a string str from (x,y) |
Rhyme | 0:94253645a02a | 62 | * @param *str c-style string to be written |
Rhyme | 0:94253645a02a | 63 | * @param x column of the first letter |
Rhyme | 0:94253645a02a | 64 | * @param y row of the first letter |
Rhyme | 0:94253645a02a | 65 | */ |
Rhyme | 0:94253645a02a | 66 | void putStr(int x, int y, char *str) ; |
Rhyme | 0:94253645a02a | 67 | |
Rhyme | 0:94253645a02a | 68 | /** print a line of char |
Rhyme | 0:94253645a02a | 69 | * @param c the letter to form the line |
Rhyme | 0:94253645a02a | 70 | * @param x1 starting column |
Rhyme | 0:94253645a02a | 71 | * @param y1 starting row |
Rhyme | 0:94253645a02a | 72 | * @param x2 ending column |
Rhyme | 0:94253645a02a | 73 | * @param y2 ending row |
Rhyme | 0:94253645a02a | 74 | */ |
Rhyme | 0:94253645a02a | 75 | void line(int x1, int y1, int x2, int y2, char c='*') ; |
Rhyme | 0:94253645a02a | 76 | |
Rhyme | 0:94253645a02a | 77 | /** print a text frame |
Rhyme | 0:94253645a02a | 78 | * @param x1 left column |
Rhyme | 0:94253645a02a | 79 | * @param y1 top row |
Rhyme | 0:94253645a02a | 80 | * @param x2 right column |
Rhyme | 0:94253645a02a | 81 | * @param y2 bottom row |
Rhyme | 0:94253645a02a | 82 | */ |
Rhyme | 0:94253645a02a | 83 | void frame(int x1, int y1, int x2, int y2) ; |
Rhyme | 0:94253645a02a | 84 | |
Rhyme | 0:94253645a02a | 85 | /** print a text circle |
Rhyme | 0:94253645a02a | 86 | * @c the letter to form the circle |
Rhyme | 0:94253645a02a | 87 | * @param x0 center column |
Rhyme | 0:94253645a02a | 88 | * @param y1 center row |
Rhyme | 0:94253645a02a | 89 | * @param r radius |
Rhyme | 0:94253645a02a | 90 | */ |
Rhyme | 0:94253645a02a | 91 | void circle(int x0, int y0, int r, char c='*') ; |
Rhyme | 0:94253645a02a | 92 | |
Rhyme | 0:94253645a02a | 93 | /** set foreground color |
Rhyme | 0:94253645a02a | 94 | * @param newFG new foreground color |
Rhyme | 0:94253645a02a | 95 | * @returns previous foreground color |
Rhyme | 0:94253645a02a | 96 | * @note 0 BLACK |
Rhyme | 0:94253645a02a | 97 | * @note 1 RED |
Rhyme | 0:94253645a02a | 98 | * @note 2 GREEN |
Rhyme | 0:94253645a02a | 99 | * @note 3 YELLOW |
Rhyme | 0:94253645a02a | 100 | * @note 4 BLUE |
Rhyme | 0:94253645a02a | 101 | * @note 5 PURPLE |
Rhyme | 0:94253645a02a | 102 | * @note 6 CIAN |
Rhyme | 0:94253645a02a | 103 | * @note 7 WHITE |
Rhyme | 0:94253645a02a | 104 | */ |
Rhyme | 0:94253645a02a | 105 | int setFG(int newFG) ; |
Rhyme | 0:94253645a02a | 106 | |
Rhyme | 0:94253645a02a | 107 | /** get current foreground color |
Rhyme | 0:94253645a02a | 108 | * @returns current foreground color |
Rhyme | 0:94253645a02a | 109 | */ |
Rhyme | 0:94253645a02a | 110 | int getFG(void) ; |
Rhyme | 0:94253645a02a | 111 | |
Rhyme | 0:94253645a02a | 112 | /** set background color |
Rhyme | 0:94253645a02a | 113 | * @param newBG new background color |
Rhyme | 0:94253645a02a | 114 | * @returns previous background color |
Rhyme | 0:94253645a02a | 115 | */ |
Rhyme | 0:94253645a02a | 116 | int setBG(int newBG) ; |
Rhyme | 0:94253645a02a | 117 | |
Rhyme | 0:94253645a02a | 118 | /** get current background color |
Rhyme | 0:94253645a02a | 119 | * @returns current background color |
Rhyme | 0:94253645a02a | 120 | */ |
Rhyme | 0:94253645a02a | 121 | int getBG(void) ; |
Rhyme | 0:94253645a02a | 122 | /** set foreground color to black */ |
Rhyme | 0:94253645a02a | 123 | void black(void) ; |
Rhyme | 0:94253645a02a | 124 | /** set foreground color to red */ |
Rhyme | 0:94253645a02a | 125 | void red(void) ; |
Rhyme | 0:94253645a02a | 126 | /** set foreground color to green */ |
Rhyme | 0:94253645a02a | 127 | void green(void) ; |
Rhyme | 0:94253645a02a | 128 | /** set foreground color to yellow */ |
Rhyme | 0:94253645a02a | 129 | void yellow(void) ; |
Rhyme | 0:94253645a02a | 130 | /** set foreground color to blue */ |
Rhyme | 0:94253645a02a | 131 | void blue(void) ; |
Rhyme | 0:94253645a02a | 132 | /** set foreground color to purple */ |
Rhyme | 0:94253645a02a | 133 | void purple(void) ; |
Rhyme | 0:94253645a02a | 134 | /** set foreground color to cian */ |
Rhyme | 0:94253645a02a | 135 | void cian(void) ; |
Rhyme | 0:94253645a02a | 136 | /** set foreground color to white */ |
Rhyme | 0:94253645a02a | 137 | void white(void) ; |
Rhyme | 0:94253645a02a | 138 | protected: |
Rhyme | 0:94253645a02a | 139 | private: |
Rhyme | 0:94253645a02a | 140 | int foreground ; |
Rhyme | 0:94253645a02a | 141 | int background ; |
Rhyme | 0:94253645a02a | 142 | |
Rhyme | 0:94253645a02a | 143 | } ; |
Rhyme | 0:94253645a02a | 144 | |
Rhyme | 0:94253645a02a | 145 | #endif /* VT100_H */ |