commit f698900597b860dc7f778883cd88a3944a303c3e
parent 90f4df08d428dc95c5046c48de83edf51fdb2f17
Author: Andy Herbert <andy.herbert@gmail.com>
Date: Tue, 15 Oct 2013 20:46:21 +0100
Added an option to re-play an ansi, without clearing the screen first.
Diffstat:
M | ansilove.js | | | 84 | ++++++++++++++++++++++++++++++++++++++++++++----------------------------------- |
1 file changed, 47 insertions(+), 37 deletions(-)
diff --git a/ansilove.js b/ansilove.js
@@ -1109,8 +1109,32 @@ var AnsiLove = (function () {
});
}
- function Ansimation(file, canvas, ctx, font, icecolors, palette) {
- var blinkCanvas, buffer, bufferCtx, blinkCtx, escaped, escapeCode, j, code, values, x, y, savedX, savedY, foreground, background, drawForeground, drawBackground, bold, inverse, blink;
+ function Ansimation(bytes, options) {
+ var timer, interval, file, font, icecolors, bits, palette, canvas, ctx, blinkCanvas, buffer, bufferCtx, blinkCtx, escaped, escapeCode, j, code, values, x, y, savedX, savedY, foreground, background, drawForeground, drawBackground, bold, inverse, blink;
+
+ file = new File(bytes);
+ icecolors = options.icecolors || false;
+ bits = options.bits || 8;
+
+ switch (bits) {
+ case "ced":
+ palette = Palette.CED;
+ break;
+ case "workbench":
+ palette = Palette.WORKBENCH;
+ break;
+ default:
+ palette = Palette.ANSI;
+ }
+
+ font = Font.preset(options.font) || Font.preset("80x25");
+
+ if (font.getWidth() === 9 && bits !== "9") {
+ font.setWidth(8);
+ }
+
+ canvas = createCanvas(80 * font.getWidth(), 26 * font.getHeight());
+ ctx = canvas.getContext("2d");
blinkCanvas = [createCanvas(canvas.width, canvas.height), createCanvas(canvas.width, canvas.height)];
buffer = createCanvas(canvas.width, canvas.height);
@@ -1169,6 +1193,8 @@ var AnsiLove = (function () {
file.seek(0);
}
+ resetAll();
+
function getValues() {
return escapeCode.substr(1, escapeCode.length - 2).split(";").map(function (value) {
var parsedValue;
@@ -1320,8 +1346,10 @@ var AnsiLove = (function () {
}
return {
- "play": function (baud, callback) {
- var timer, interval, length, drawBlink;
+ "canvas": canvas,
+ "play": function (baud, callback, clearScreen) {
+ var length, drawBlink;
+ clearScreen = (clearScreen === undefined) ? true : clearScreen;
clearTimeout(timer);
clearInterval(interval);
drawBlink = false;
@@ -1337,47 +1365,29 @@ var AnsiLove = (function () {
}
}
length = Math.floor((baud || 115200) / 8 / 100);
- resetAll();
+ if (clearScreen) {
+ resetAll();
+ } else {
+ resetAttributes();
+ escapeCode = "";
+ escaped = false;
+ file.seek(0);
+ }
drawChunk();
- }
+ },
+ "sauce": file.sauce
};
}
function animate(url, callback, options) {
- var ansimation, icecolors, bits, font, palette;
- if (options) {
- icecolors = options.icecolors || false;
- bits = options.bits || 8;
- font = Font.preset(options.font || "80x25");
- } else {
- icecolors = false;
- bits = 8;
- font = Font.preset("80x25");
- }
- if (font.getWidth() === 9 && bits !== "9") {
- font.setWidth(8);
- }
- switch (bits) {
- case "ced":
- palette = Palette.CED;
- break;
- case "workbench":
- palette = Palette.WORKBENCH;
- break;
- default:
- palette = Palette.ANSI;
- }
+ var ansimation;
httpGet(url, function (bytes) {
- var file, canvas, ctx;
- file = new File(bytes);
- canvas = createCanvas(80 * font.getWidth(), 26 * font.getHeight());
- ctx = canvas.getContext("2d");
- ansimation = new Ansimation(file, canvas, ctx, font, icecolors, palette);
- callback(canvas, file.sauce);
+ ansimation = new Ansimation(bytes, options || {});
+ callback(ansimation.canvas, ansimation.sauce);
});
return {
- "play": function (baud, callback) {
- ansimation.play(baud, callback);
+ "play": function (baud, callback, clearScreen) {
+ ansimation.play(baud, callback, clearScreen);
}
};
}