VT100 Terminal

A simple library for controlling the cursor position and colour on a serial terminal emulator.

/media/uploads/simon/terminal2.png

Hello World!

» Import this program

00001 // simple test for a ANSI/VT100 Terminal, sford
00002 
00003 #include "mbed.h"
00004 #include "Terminal.h"
00005 
00006 Terminal term(USBTX, USBRX); // tx, rx
00007 
00008 int main() {
00009     term.printf("Hello World!\nHow are you?");
00010 
00011     wait(2);
00012 
00013     term.locate(3,1);
00014     term.foreground(0xFF0000);
00015     term.printf("I'm Great!");
00016 
00017     wait(3);
00018 
00019     term.cls();
00020 }

Library

» Import this library into a program

Public Member Functions

  Terminal (PinName tx, PinName rx)
  Create the Terminal interface.
int  putc (int c)
  Write a character to the terminal.
int  printf (const char *format,...)
  Write a formated string to the terminal.
void  locate (int column, int row)
  Locate to a screen column and row.
void  cls ()
  Clear the screen and locate to 0,0.
void  foreground (int colour)
  Set the foreground colour.
void  background (int colour)
  Set the background colour.

Details

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:

Reference





4 comments:

06 Dec 2010

Where is Terminal.h

07 Nov 2011

Hi Martin, in case you still have not got it. There is a link » Import this library into a program

This is right where the Library interface is explained.

02 Nov 2012

My code hangs until I change this line in locate:

this->printf("\033[%d;%dH%c", row + 1, column + 1);

to

this->printf("\033[%d;%dH", row + 1, column + 1);

It worked for awhile until something changed recently?

10 Nov 2012

These functions are also handy for low-res plots using ASCII characters. Here is an example using the VT100 locate() function calls to plot data from mbed's A/D. A cls() is used to initially clear the screen.

/media/uploads/4180_1/_scaled_mbedscope.png


When drawing images using characters, special ASCII graphics characters can also be used.