VT100 Terminal Emulator
VT100 (About Modules) is a VT100 terminal emulator - it takes a series of characters and draws them on a Graphics object, interpretering newline/carriage return/up/down/left/right/etc correctly.
It isn't a full emulator, but emulates enough of a terminal to correctly display everything that comes out of Espruino.
The main use for this is allow you to display Espruino's console on a screen connected to Espruino itself.
To do this you'd want to use LoopbackA
and LoopbackB
:
// take characters from Espruino, and push them into the VT100 terminal
LoopbackB.on('data',function(e){
// USB.write(e); // optionally mirror back to the PC
// Send characters to the terminal
for (var i in e) term.char(e[i]);
// update the screen
g.flip();
});
// copy characters coming down USB into the 'loopback' device
USB.on('data',function(e){ LoopbackB.write(e); });
// Now move the console to Loopback
LoopbackA.setConsole();
For example, assuming you have an LCD connected as described in the Pico LCD Hello World tutorial:
A5.write(0); // LCD GND
A7.write(1); // LCD VCC
A6.write(1); // TLCD backlight
var g; // Graphics
var term; // the terminal
function onInit() {
// Setup SPI for LCD
var spi = new SPI();
spi.setup({ sck:B1, mosi:B10 });
// Initialise the LCD
g = require("PCD8544").connect(spi,B13,B14,B15, function() {
// LCD initialised...
// Set up the terminal
term = require("VT100").connect(g, {
charWidth : 4,
charHeight : 8
});
// take characters from Espruino, and push them into the VT100 terminal
LoopbackB.on('data',function(e){
// USB.write(e); // optionally mirror back to the PC
// Send characters to the terminal
for (var i in e) term.char(e[i]);
// update the screen
g.flip();
});
// copy characters coming down USB into the 'loopback' device
USB.on('data',function(e){ LoopbackB.write(e); });
// Now move the console to Loopback
LoopbackA.setConsole();
});
}
You'll need to manually run onInit()
after uploading.
If you were to then add a keyboard to Espruino, you would have a complete computer!
Reference
// Draw an underline under the current character
VT100.prototype.drawCursor = function () { ... }
// Scroll the screen down (if possible, else clear)
VT100.prototype.scrollDown = function () { ... }
// Call this every time you get a character (ch is a single-character string)
VT100.prototype.char = function (ch) { ... }
/* Create a VT100-style terminal.
g = Graphics to use
options = object of options:
charWidth -> width of characters in pixels
charHeight -> height of characters in pixels
marginLeft -> left margin (we have no right margin)
marginTop -> top margin
marginBottom -> bottom margin
After setting up, you can also set:
term.fgCol -> Foreground color
term.bgCol -> Background color
*/
exports.connect = function (g, options) { ... }
Using
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.