Terminal
.
A simple library for controlling the cursor position and colour on a serial terminal emulator.
A terminal program like Teraterm or Hyperterminal often supports escape sequences to control things like cursor location and colour. A common set of escape codes are those first used on the VT100 terminal, which are listed sequences, as found here:
Based on the conversation about the TextStar LCD, this is an experiment for a very simple library to wrap these up in to a class inherited from Serial to make it much easier to use, and more like the drivers we'll have for LCDs.
ANSI/VT100 Terminal Library and Example
Screenshots
#include "mbed.h" #include "Terminal.h" Terminal term(USBTX, USBRX); // tx, rx int main() { term.background(0x00FF00); term.foreground(0xFF0000); term.printf("Hello"); term.locate(3,3); term.foreground(0x0000FF); term.printf("World!"); }
![](http://mbed.org/media/uploads/simon/terminal1.png)
#include "mbed.h" #include "Terminal.h" Terminal term(USBTX, USBRX); // tx, rx #define ASCII_BLOCK 219 #define ASCII_BORDER_H 205 #define ASCII_BORDER_V 186 #define ASCII_BORDER_TL 201 #define ASCII_BORDER_TR 187 #define ASCII_BORDER_BL 200 #define ASCII_BORDER_BR 188 #define WIDTH 30 void box(int x, int y, int w, int h) { // corners term.locate(x, y); term.putc(ASCII_BORDER_TL); term.locate(x + w - 1, y); term.putc(ASCII_BORDER_TR); term.locate(x, y + h - 1); term.putc(ASCII_BORDER_BL); term.locate(x + w - 1, y + h - 1); term.putc(ASCII_BORDER_BR); // top term.locate(x + 1, y); for(int i=0; i
![](http://mbed.org/media/uploads/simon/terminal2.png)
3 comments
You need to log in to post a comment
Hey..! Maybe someone can start porting dos games now haha. This is very nice..